UNPKG

svelte-query-params

Version:

A lightweight, dead-simple, type-safe reactive query parameter store built for Svelte 5.

22 lines (21 loc) 617 B
// src/lib/adapters/browser.ts function browser(options = {}) { const { windowObj = window, replace = false } = options; const replaceState = windowObj.history.replaceState.bind(windowObj.history); const pushState = windowObj.history.pushState.bind(windowObj.history); const update = replace ? replaceState : pushState; return { isBrowser: () => typeof window !== "undefined", browser: { read: () => windowObj.location, save: (search, hash) => update(null, "", `${search.length ? search : "?"}${hash}`) }, server: { save: () => { } } }; } export { browser };