This commit is contained in:
syuilo 2021-11-20 11:47:19 +09:00
parent 043ffe3a2e
commit de81437248

View file

@ -1,13 +1,17 @@
import autobind from 'autobind-decorator'; import autobind from 'autobind-decorator';
import { EventEmitter } from 'eventemitter3'; import { EventEmitter } from 'eventemitter3';
import ReconnectingWebsocket from 'reconnecting-websocket'; import ReconnectingWebsocket from 'reconnecting-websocket';
import { stringify } from 'querystring';
import { BroadcastEvents, Channels } from './streaming.types'; import { BroadcastEvents, Channels } from './streaming.types';
function urlQuery(obj: Record<string, unknown>): string { export function urlQuery(obj: Record<string, unknown>): string {
return stringify(Object.entries(obj) const params = Object.entries(obj)
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined) .filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined)
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>)); .reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, unknown>);
return Object.entries(params)
.map((e) => `${e[0]}=${e[1]}`)
.map((e) => `${e[0]}=${encodeURIComponent(e[1])}`)
.join('&');
} }
type AnyOf<T extends Record<any, any>> = T[keyof T]; type AnyOf<T extends Record<any, any>> = T[keyof T];