/** * @jorvel/runtime — typed search-param helpers. * * Validate and serialize URL query strings into typed objects using a minimal, * standard-schema-style validator. ANY library that exposes `parse(input)` — * Zod, Valibot, Yup wrappers, or a hand-written object — conforms. We do NOT * depend on zod. * * Exports: * - `Validator` — the minimal `{ parse(input:unknown):T }` contract * - `createSearchSchema(v)` — wrap a validator into a reusable schema with * `parse` / `serialize` helpers * - `parseSearchParams(s, v)` — URLSearchParams | string → typed `T` * - `buildSearchString(vals)` — typed object → `"a=1&b=2"` (no leading `?`) * - `useTypedSearchParams(v)` — React hook → `[typed, setTyped]`, SSR-safe, * built on the existing `useSearchParams` hook * * SSR-safe: parsing/serialization touch no browser globals; the hook reads the * router (which falls back to the server router under SSR) and never assumes * `window` at module scope. */ import type { Validator } from './typed-routes.js'; /** A reusable typed-search schema produced by {@link createSearchSchema}. */ export interface SearchSchema { /** Underlying validator. */ readonly validator: Validator; /** URLSearchParams | string → typed `T`. */ parse: (search: string | URLSearchParams) => T; /** typed `T` → query string (no leading `?`). */ serialize: (values: T) => string; } /** * Parse a query string / URLSearchParams into a typed object via `validator`. * The raw entries are passed as a `Record`, so a validator that * coerces (e.g. `page: "2"` → `2`) works as expected. */ export declare function parseSearchParams(search: string | URLSearchParams, validator: Validator): T; /** * Serialize a typed object into a query string (no leading `?`). `null` / * `undefined` values are dropped; arrays expand to repeated keys; everything * else is `String()`-coerced. */ export declare function buildSearchString(values: Record): string; /** * Wrap a validator into a reusable schema. Handy to define once and share * between a loader, a link builder, and {@link useTypedSearchParams}. */ export declare function createSearchSchema(validator: Validator): SearchSchema; export interface UseTypedSearchParamsOptions { /** Use `history.replaceState` instead of `push` when writing. Default false. */ replace?: boolean; } /** * React hook returning `[typed, setTyped]`. `typed` is the current query string * parsed through `validator`; `setTyped` serializes the next value and * navigates. Built on the existing {@link useSearchParams} hook so it shares the * router's reactivity and SSR behavior. * * `setTyped` accepts either the next values or an updater `(prev) => next`. */ export declare function useTypedSearchParams(validator: Validator, options?: UseTypedSearchParamsOptions): [T, (next: T | ((prev: T) => T)) => void]; //# sourceMappingURL=search-params.d.ts.map