validation
Standard Schema utilities and ValidationError helpers for one consistent validation flow across schema libraries.
validation provides utilities for validating values using the Standard Schema specification.
Motivation
Zod throws a ZodError. Valibot returns a result object. ArkType has its own shape. If your code — or a library you are writing — needs to support more than one of these, or wants to let its users bring whichever one they prefer, you end up writing different error-handling code for each.
And if you ever switch from one to another, every call site that touches validation needs to change too.
validation removes this difference. standardValidate and standardValidateSync give you one function and one ValidationError shape, no matter which Standard Schema library sits underneath.
Validation code becomes portable: swap the schema library later, and the code that calls it does not need to change.
Features
- Async-safe validation via
standardValidate, works with sync and async schemas. - Synchronous validation via
standardValidateSync, for schemas known to validate synchronously. - Reusable validators via
createStandardValidatorandcreateStandardValidatorSync. - Optional throwing behavior via
throwOnError, backed by a sharedValidationErrorclass. - Runtime schema detection via
isStandardSchema. - Type re-exports —
StandardSchemaV1andStandardTypedV1directly from this package. - Tree-shakeable — every helper is a standalone function; unused exports are dropped by any modern bundler.
Quick Start
import { standardValidate } from "@zap-studio/validation";
// `userSchema` can come from any Standard Schema-compatible library
try {
const user = await standardValidate(input, userSchema, {
throwOnError: true,
});
console.log("Validation passed:", user);
} catch (error) {
console.error("Validation failed:", error);
}
Learn More
- Getting Started — install and validate your first payload
- Async Validation —
standardValidate - Synchronous Validation —
standardValidateSync - Create Validators — reusable validator functions
- Errors —
throwOnErrorandValidationError - Runtime Schema Detection —
isStandardSchema
Runtime Support
| Runtime | Minimum version |
|---|---|
| Node.js | 18.0.0 |
| Bun | 1.0.0 |
| Deno | 1.42 |
| Cloudflare Workers | Any current release |
| Browsers | Latest evergreen (Chrome, Edge, Firefox, Safari) |
The package ships standard ESM only and uses no runtime-specific APIs. Deno 1.42 is the first release that can install packages from JSR (deno add jsr:@zap-studio/validation).