All built-in parsers are exported from the main nuqs package and implement the SingleParserBuilder interface, providing access to .withDefault() and .withOptions() methods.
String Parsers
parseAsString
Parses and serializes string values (identity parser).
Implementation:
From: packages/nuqs/src/parsers.ts:230-233
Usage:
Behavior:
- Parse: Returns the input string as-is
- Serialize: Converts value to string using
String()
- Invalid input: Never returns
null (all strings are valid)
Number Parsers
parseAsInteger
Parses integers and serializes with rounding.
Implementation:
From: packages/nuqs/src/parsers.ts:235-241
Usage:
Behavior:
- Parse: Uses
parseInt(), returns null for NaN
- Serialize: Rounds to nearest integer with
Math.round()
- Invalid input:
'', 'abc', '3.14.15' → null
parseAsFloat
Parses floating-point numbers with full precision.
Implementation:
From: packages/nuqs/src/parsers.ts:262-268
Usage:
Behavior:
- Parse: Uses
parseFloat(), returns null for NaN
- Serialize: Uses
String() to preserve precision
- Invalid input:
'', 'abc' → null
parseAsHex
Parses hexadecimal numbers.
Implementation:
From: packages/nuqs/src/parsers.ts:251-260
Usage:
Behavior:
- Parse: Uses
parseInt(v, 16) for hexadecimal conversion
- Serialize: Converts to hex string, zero-pads to even length
- Invalid input:
'', 'xyz' → null
parseAsIndex
Parses 1-based indices and stores them as 0-based.
Implementation:
From: packages/nuqs/src/parsers.ts:243-249
Usage:
Behavior:
- Parse: Subtracts 1 to convert from 1-based to 0-based
- Serialize: Adds 1 to convert from 0-based to 1-based, rounds
- Use case: User-facing page numbers, tab indices
Boolean Parser
parseAsBoolean
Parses boolean values (case-insensitive 'true' only).
Implementation:
From: packages/nuqs/src/parsers.ts:270-273
Usage:
Behavior:
- Parse: Returns
true only for 'true' (case-insensitive), otherwise false
- Serialize: Uses
String() to produce 'true' or 'false'
- Invalid input: All input is valid - non-
'true' values return false
- Note:
'yes', '1', 'on' all parse as false
Date & Time Parsers
All date parsers use a custom equality function:
From: packages/nuqs/src/parsers.ts:275-277
parseAsTimestamp
Parses Unix timestamps (milliseconds since epoch).
Implementation:
From: packages/nuqs/src/parsers.ts:283-290
Usage:
Behavior:
- Parse: Converts millisecond timestamp to
Date object
- Serialize: Converts
Date to milliseconds with valueOf()
- Invalid input:
'', 'abc' → null
parseAsIsoDateTime
Parses ISO-8601 datetime strings with timezone.
Implementation:
From: packages/nuqs/src/parsers.ts:296-304
Usage:
Behavior:
- Parse: Uses
new Date(v) constructor, returns null for invalid dates
- Serialize: Uses
toISOString() for full precision with timezone
- Invalid input:
'', 'not-a-date' → null
parseAsIsoDate
Parses ISO-8601 date strings (YYYY-MM-DD) without time.
Implementation:
From: packages/nuqs/src/parsers.ts:314-322
Usage:
Behavior:
- Parse: Takes first 10 characters (YYYY-MM-DD), creates Date at 00:00:00 UTC
- Serialize: Extracts date portion from ISO string
- Invalid input:
'', 'not-a-date' → null
Enum & Literal Parsers
parseAsStringEnum
Parses string-based TypeScript enums.
Implementation:
From: packages/nuqs/src/parsers.ts:351-356
Usage:
Behavior:
- Parse: Returns value if it matches one of
validValues, otherwise null
- Serialize: Uses
String() on the enum value
- Invalid input: Values not in
validValues → null
parseAsStringLiteral
Parses string literal unions.
Implementation:
From: packages/nuqs/src/parsers.ts:377-387
Usage:
Behavior:
- Parse: Returns value if in
validValues, otherwise null
- Serialize: Uses
String() on the literal
- Type safety: Requires
as const assertion for proper type inference
parseAsNumberLiteral
Parses number literal unions.
Implementation:
From: packages/nuqs/src/parsers.ts:408-421
Usage:
Behavior:
- Parse: Uses
parseFloat(), returns value if in validValues, otherwise null
- Serialize: Uses
String() on the number
- Type safety: Requires
as const assertion
Collection Parsers
parseAsArrayOf
Parses comma-separated arrays with URI encoding.
Implementation:
From: packages/nuqs/src/parsers.ts:466-510
Usage:
Behavior:
- Parse: Splits by separator, parses each item, filters out
null values
- Serialize: Serializes each item, URI-encodes separator characters, joins
- Invalid items: Filtered out (array contains only valid items)
- Empty array: Serializes to empty string
''
parseAsNativeArrayOf
Parses native array query parameters (e.g., ?tag=a&tag=b&tag=c).
Implementation:
From: packages/nuqs/src/parsers.ts:512-541
Usage:
Behavior:
- Parse: Parses array of query values, filters out
null, returns null if empty
- Serialize: Returns array of strings for repeated parameters
- Default: Always includes
.withDefault([]) for non-nullable arrays
- Invalid items: Filtered out
JSON Parser
parseAsJson
Parses JSON-encoded objects with optional runtime validation.
Implementation:
From: packages/nuqs/src/parsers.ts:430-457
Usage:
Behavior:
- Parse: Parses JSON, validates with schema/function, returns
null on error
- Serialize: Uses
JSON.stringify()
- Equality: Compares referential equality first, then serialized JSON
- Validation: Supports Standard Schema (Zod, Valibot, ArkType) or custom functions
- Invalid input: Malformed JSON or validation failure →
null
Always validate JSON data with a schema library. Unvalidated JSON can introduce type safety issues.
Next Steps