export function getUrlParams() { if (typeof window === 'undefined') { return {}; } const params = new URLSearchParams(window.location.search); const paramsObj: Record = {}; for (const [key, value] of params.entries()) { paramsObj[key] = value; } return paramsObj; } export function deleteUrlParam(key: string) { if (typeof window === 'undefined') { return; } const url = new URL(window.location.href); if (!url.searchParams.has(key)) { return; } url.searchParams.delete(key); window.history.pushState(null, '', url.toString()); } export function setUrlParams(params: Record) { if (typeof window === 'undefined') { return; } const url = new URL(window.location.href); let hasUpdatedUrl = false; for (const [key, value] of Object.entries(params)) { if (url.searchParams.get(key) === String(value)) { continue; } url.searchParams.delete(key); url.searchParams.set(key, value); hasUpdatedUrl = true; } if (hasUpdatedUrl) { window.history.pushState(null, '', url.toString()); } }