Public source validation / validate (push) Failing after 3m8s
16 lines
734 B
TypeScript
16 lines
734 B
TypeScript
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}` : ''));
|
|
}
|