2019-02-13 23:45:35 +09:00
|
|
|
import { stringify } from 'querystring';
|
|
|
|
|
|
|
|
export function query(obj: {}): string {
|
|
|
|
return stringify(Object.entries(obj)
|
|
|
|
.filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined)
|
|
|
|
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>));
|
|
|
|
}
|
2019-03-18 13:20:49 +09:00
|
|
|
|
|
|
|
export function appendQuery(url: string, query: string): string {
|
|
|
|
return `${url}${/\?/.test(url) ? url.endsWith('?') ? '' : '&' : '?'}${query}`;
|
|
|
|
}
|