refactor: prelude/urlでquerystringを使用しないように

Resolve #7854
This commit is contained in:
syuilo 2021-10-01 00:31:43 +09:00
parent 4fd4132f5e
commit bd9df789d1

View file

@ -1,9 +1,11 @@
import { stringify } from 'querystring';
export function query(obj: {}): string { export function query(obj: {}): 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, any>);
return Object.entries(params)
.map((e) => `${e[0]}=${e[1]}`)
.join('&');
} }
export function appendQuery(url: string, query: string): string { export function appendQuery(url: string, query: string): string {