parseAsStandardSchema
function parseAsStandardSchema<T>(schema, options?): Parser<T>;Defined in: tanstack/core/built-in-parsers.ts:460
Validate the raw query string through a Standard Schema (Zod, Valibot,
ArkType, …) and return its output; invalid input → null. Best for scalar
params (z.string().email(), z.coerce.number(), z.enum([...])); for
structured values prefer parseAsJson(schema). Validation must be sync.
Without options.serialize, strings are written as-is and other values as
JSON; equality defaults to comparing JSON.stringify output.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
schema |
StandardSchemaV1<unknown, T> |
options? |
{ eq?: (a, b) => boolean; serialize?: (value) => string; } |
options.eq? |
(a, b) => boolean |
options.serialize? |
(value) => string |
Returns
Section titled “Returns”Parser<T>
Example
Section titled “Example”import { parseAsStandardSchema } from "@xtandard/lib/tanstack";import { z } from "zod";
const email = parseAsStandardSchema(z.string().email());email.parse("nope"); // → null
const qty = parseAsStandardSchema(z.coerce.number().int().min(1));qty.parse("3"); // → 3qty.parse("0"); // → nullqty.serialize(3); // → "3"