parent
037837b551
commit
0e4a111f81
1714 changed files with 20803 additions and 11751 deletions
13
packages/client/src/scripts/url.ts
Normal file
13
packages/client/src/scripts/url.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
export function query(obj: {}): 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>);
|
||||
|
||||
return Object.entries(params)
|
||||
.map((e) => `${e[0]}=${encodeURIComponent(e[1])}`)
|
||||
.join('&');
|
||||
}
|
||||
|
||||
export function appendQuery(url: string, query: string): string {
|
||||
return `${url}${/\?/.test(url) ? url.endsWith('?') ? '' : '&' : '?'}${query}`;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue