mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature] prepare shortcut creation
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export function objectFromEntries<T>(entries: Iterable<readonly [PropertyKey, T]>): Record<PropertyKey, T | T[]> {
|
||||
const temp: Record<PropertyKey, T | T[]> = {};
|
||||
|
||||
for (const [key, value] of entries) {
|
||||
if (temp[key]) {
|
||||
temp[key] = Array.isArray(temp[key]) ? [...(temp[key] as T[]), value] : [(temp[key] as T), value];
|
||||
} else {
|
||||
temp[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
@@ -6,3 +6,30 @@ export function isValidUrl(url: string): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function buildUrl({
|
||||
protocol = "https",
|
||||
host = "about:blank",
|
||||
path = "",
|
||||
search = {},
|
||||
hash = ""
|
||||
}: {
|
||||
protocol?: string,
|
||||
host?: string,
|
||||
path?: string,
|
||||
search?: Record<string, string | string[]>,
|
||||
hash?: string
|
||||
}): URL {
|
||||
const url = new URL(`${protocol}://${host}${path}`);
|
||||
url.hash = hash;
|
||||
|
||||
for (const [key, value] of Object.entries(search)) {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => url.searchParams.append(key, v));
|
||||
} else {
|
||||
url.searchParams.append(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user