/** Next 16 search params arrive as `Promise>`; these helpers read them safely. */ export type SP = Record; export function str(v: string | string[] | undefined): string | undefined { if (Array.isArray(v)) return v[0]; return v === '' ? undefined : v; } export function int(v: string | string[] | undefined, fallback: number, min = 1, max = 100000): number { const n = Number(str(v)); if (!Number.isFinite(n)) return fallback; return Math.min(max, Math.max(min, Math.floor(n))); } export function bool(v: string | string[] | undefined): boolean { const s = str(v); return s === '1' || s === 'true'; } /** Current params as a flat string record (for `withParams`). */ export function flat(sp: SP): Record { const out: Record = {}; for (const [k, v] of Object.entries(sp)) out[k] = str(v); return out; }