data-schema package provides tiny, standards-aligned data validation for Remix applications. It’s Standard Schema v1 compatible, sync-first, and runs anywhere JavaScript runs.
Installation
Parsing
parse()
Useparse() when you want a typed value or an exception:
parseSafe()
UseparseSafe() when you prefer explicit branching over exceptions:
Primitive Types
Objects
Unknown Keys
By default, unknown keys are stripped. Change this withunknownKeys:
Collections
Literals, Enums, and Unions
Validation Checks
Compose reusable checks with.pipe():
Built-in Checks
minLength(min)- String/array minimum lengthmaxLength(max)- String/array maximum lengthemail()- Valid email formaturl()- Valid URL formatmin(value)- Number/bigint minimum valuemax(value)- Number/bigint maximum value
Custom Checks with .refine()
Add domain-specific validation inline:Coercion
Turn stringly-typed inputs (like form data or query strings) into real types:Discriminated Unions
Pick the right schema based on a discriminator property:Recursive Schemas
Model trees and self-referencing structures withlazy():
Custom Error Messages
Customize validation messages witherrorMap:
errorMap receives { code, defaultMessage, path, values, input, locale }.
Abort Early
By default, validation collects all issues. Stop at the first issue withabortEarly:
Type Inference
Extract input and output types from schemas:Table Validation
Integrate schema validation withdata-table:
Custom Schemas
Build custom schemas usingcreateSchema, createIssue, and fail: