Files
ITWorx-Pulse-Public/apps/web/src/listQuery.ts
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

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}` : ''));
}