This commit is contained in:
commit
bd774932d5
614 files changed
+77116
No files matched your search
@@ -0,0 +1,15 @@
|
||||
export function queryValue(name: string, allowed?: readonly string[], fallback = ''): string {
|
||||
if (typeof window === 'undefined') return fallback;
|
||||
const value = new URLSearchParams(window.location.search).get(name) ?? fallback;
|
||||
return !allowed || allowed.includes(value) ? value : fallback;
|
||||
}
|
||||
|
||||
export function replaceListQuery(values: Record<string, string>): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
if (value) params.set(key, value); else params.delete(key);
|
||||
}
|
||||
const query = params.toString();
|
||||
window.history.replaceState({}, '', window.location.pathname + (query ? `?${query}` : ''));
|
||||
}
|
||||
Reference in new issue
Block a user