1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-14 14:48:53 +09:00
cherrypick/src/prelude/url.ts

12 lines
409 B
TypeScript
Raw Normal View History

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>));
}
export function appendQuery(url: string, query: string): string {
return `${url}${/\?/.test(url) ? url.endsWith('?') ? '' : '&' : '?'}${query}`;
}