Registry / devops / zod-urlsearchparams

zod-urlsearchparams

JSON →
library0.0.16jsnpmunverified

Serializes and deserializes a Zod schema to and from URLSearchParams. Current stable version is 0.0.16, with an experimental API that may change. It minimalizes URLs by keeping scalars human-readable and encoding vectors (like arrays and objects) with base64. Zero dependencies outside of Zod (peer dependency: zod ^3.0.0). Ships TypeScript types. Differentiator: type-safe URL parameter handling using Zod schemas, with a class-based API and lenient parsing that falls back to defaults.

npm install zod-urlsearchparams
INSTALL
IMPORT
SIG · ZOD-URLSEARCHPARAM
Z
zod-urlsearchparams
devopsjavascriptv0.0.16
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'zod-urlsearchparams'
const parse = require('zod-urlsearchparams').parse
ESM-only; named export since v0.0.1
serialize
import { serialize } from 'zod-urlsearchparams'
import { serialise } from 'zod-urlsearchparams'
Note: British spelling 'serialise' is not correct; use 'serialize'
lenientParse
import { lenientParse } from 'zod-urlsearchparams'
import { lenientparse } from 'zod-urlsearchparams'
Case-sensitive: 'lenientParse' with capital P
ZodURLSearchParamSerializer
import { ZodURLSearchParamSerializer } from 'zod-urlsearchparams'
import { ZodURLSearchParamsSerializer } from 'zod-urlsearchparams'
Class name is singular 'ParamSerializer', not 'ParamsSerializer'

Demonstrates serialize, parse, and lenientParse with a Zod schema for URLSearchParams.

import { z } from 'zod'; import { parse, serialize, lenientParse } from 'zod-urlsearchparams'; const schema = z.object({ age: z.bigint(), species: z.enum(['dog', 'cat']), interests: z.array(z.string()), location: z.object({ room: z.string() }), }); // Serialize const serialized = serialize({ schema, data: { age: BigInt(5), species: 'dog', interests: ['sleeping'], location: { room: 'kitchen' } }, }); console.log(serialized.toString()); // age=5&species=dog&interests=sleeping&location=eyJyb29tIjoia2l0Y2hlbiJ9 // Strict parse const parsed = parse({ schema, input: new URLSearchParams('age=10&species=cat&location=eyJyb29tIjoiY2F0aW8ifQ'), }); console.log(parsed); // { age: 10n, species: 'cat', interests: [], location: { room: 'catio' } } // Lenient parse with defaults const lenient = lenientParse({ schema, input: new URLSearchParams('age=10'), defaultData: { age: BigInt(0), species: 'dog', interests: [], location: { room: 'default' } }, }); console.log(lenient); // { age: 10n, species: 'dog', interests: [], location: { room: 'default' } }
Debug
Known issues
breakingVersion 0.0.x may have breaking changes at any time; no semver guarantees.
fix
Pin to exact version or watch for changes.
affects: >=0.0.0 <0.1.0
gotchaVectors (arrays, objects) are base64-encoded in the URL, not human-readable. This may be unexpected.
fix
Understand that only scalars are plain text; nested structures become base64. For readability, flatten your schema.
affects: >=0.0.0
deprecatedThe class-based API may be deprecated in future versions; the functional API is preferred.
fix
Use parse, serialize, lenientParse functions instead of ZodURLSearchParamSerializer.
affects: >=0.0.0
gotchaImport names are case-sensitive: 'lenientParse' (not 'lenientparse'), 'serialize' (not 'serialise').
fix
Use exact imports as shown in documentation.
affects: >=0.0.0
breakingRequires zod peer dependency version ^3.0.0. Incompatible with zod v2.x.
fix
Install zod 3.x alongside.
affects: >=0.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using require() on an ESM-only package.
fix
Use import syntax or switch to dynamic import().
TypeError: (0 , zod_urlsearchparams.parse) is not a function
Incorrect import: using default export instead of named import.
fix
Use import { parse } from 'zod-urlsearchparams'.
ZodError: Invalid input: expected bigint, received string
Parsing a string URL param into a bigint field without proper type coercion.
fix
Ensure the URL param is a numeric string; zod-urlsearchparams handles conversion from string to bigint automatically.
Upgrade
Version history
0.0.16latest on npm
Audit
Dependencies
zodrequiredpeer dependency: zod is required for schema definition and validation
Agent activity
24 hits · last 30 days
node
22
Resources
zod-urlsearchparams — npm install zod-urlsearchparams · libregistry