Skip to content

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 Parameter
T
Parameter Type
schema StandardSchemaV1<unknown, T>
options? { eq?: (a, b) => boolean; serialize?: (value) => string; }
options.eq? (a, b) => boolean
options.serialize? (value) => string

Parser<T>

import { parseAsStandardSchema } from "@xtandard/lib/tanstack";
import { z } from "zod";
const email = parseAsStandardSchema(z.string().email());
email.parse("[email protected]"); // → "[email protected]"
email.parse("nope"); // → null
const qty = parseAsStandardSchema(z.coerce.number().int().min(1));
qty.parse("3"); // → 3
qty.parse("0"); // → null
qty.serialize(3); // → "3"