mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
chore(core): add tests for toURLSearchParams (#8322)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
import { isNil } from 'lodash-es';
|
||||
|
||||
interface AppUrlOptions {
|
||||
desktop?: boolean | string;
|
||||
@@ -32,25 +31,3 @@ export function buildAppUrl(path: string, opts: AppUrlOptions = {}) {
|
||||
return new URL(path, webBase).toString();
|
||||
}
|
||||
}
|
||||
|
||||
export function toURLSearchParams(
|
||||
params?: Partial<Record<string, string | string[]>>
|
||||
) {
|
||||
if (!params) return;
|
||||
|
||||
const items = Object.entries(params)
|
||||
.filter(([_, v]) => !isNil(v))
|
||||
.filter(([_, v]) => {
|
||||
if (typeof v === 'string') {
|
||||
return v.length > 0;
|
||||
}
|
||||
if (Array.isArray(v)) {
|
||||
return v.length > 0;
|
||||
}
|
||||
return false;
|
||||
}) as [string, string | string[]][];
|
||||
|
||||
return new URLSearchParams(
|
||||
items.map(([k, v]) => [k, Array.isArray(v) ? v.join(',') : v])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user