This commit is contained in:
syuilo 2021-11-20 11:47:19 +09:00
parent 043ffe3a2e
commit de81437248
1 changed files with 8 additions and 4 deletions

View File

@ -1,13 +1,17 @@
import autobind from 'autobind-decorator';
import { EventEmitter } from 'eventemitter3';
import ReconnectingWebsocket from 'reconnecting-websocket';
import { stringify } from 'querystring';
import { BroadcastEvents, Channels } from './streaming.types';
function urlQuery(obj: Record<string, unknown>): string {
return stringify(Object.entries(obj)
export function urlQuery(obj: Record<string, unknown>): string {
const params = Object.entries(obj)
.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];