valrs

Introduction

TypeBox performance meets Zod ergonomics - with streaming validation

valrs

valrs is a schema validation library that combines TypeBox-level performance with Zod's developer experience. Written in Rust and compiled to WebAssembly, it delivers near-native validation speeds while providing a familiar, chainable API.

Why valrs?

Zod-Compatible API

If you know Zod, you know valrs. The API is designed to be a drop-in replacement:

import { v } from 'valrs';
 
const User = v.object({
  name: v.string().min(1).max(100),
  email: v.string().email(),
  age: v.number().int().positive(),
});
 
// Parse with runtime validation
const user = User.parse(data);
 
// Safe parsing (no throws)
const result = User.safeParse(data);
if (result.success) {
  console.log(result.data);
} else {
  console.log(result.error);
}
 
// Type inference
type User = v.infer<typeof User>;

TypeBox-Level Performance

valrs is built in Rust and compiled to WebAssembly, delivering validation speeds competitive with the fastest JavaScript validators:

Libraryops/secRelative
TypeBox22.75M1.04x
valrs21.84Mbaseline
ArkType7.73M0.35x
Valibot2.11M0.10x
Zod1.45M0.07x

Streaming Validation (Killer Feature)

Validate massive JSON files with O(1) memory. No other validation library offers this:

import { v } from 'valrs';
 
const User = v.object({
  id: v.number(),
  name: v.string(),
});
 
// Validate a 10GB file with constant memory usage
const stream = fs.createReadStream('users.json');
 
for await (const user of v.stream(v.array(User), stream)) {
  // Each user is validated as it streams through
  // Memory usage stays constant regardless of file size
  await processUser(user);
}

Full Zod Feature Parity

valrs implements the complete Zod API:

  • Primitives: string, number, bigint, boolean, date, null, undefined, void, any, unknown, never
  • Objects: object, extend, merge, pick, omit, partial, deepPartial, strict, passthrough, strip
  • Collections: array, tuple, record, map, set
  • Unions: union, discriminatedUnion, intersection, literal, enum, nativeEnum
  • Modifiers: optional, nullable, nullish, default, catch
  • Transforms: transform, refine, superRefine, pipe, preprocess, coerce

Quick Migration from Zod

Migrating from Zod is straightforward - change z to v:

// Before (Zod)
import { z } from 'zod';
 
const User = z.object({
  name: z.string(),
  email: z.string().email(),
});
 
// After (valrs)
import { v } from 'valrs';
 
const User = v.object({
  name: v.string(),
  email: v.string().email(),
});

Portability

  • Browsers: Uses WebAssembly for maximum performance
  • Node.js: Pure JavaScript fallback works everywhere
  • Edge: Compatible with Cloudflare Workers and other edge runtimes

Standards Compliance

valrs implements the Standard Schema specification v1, enabling interoperability with any tool that supports the standard.

Next Steps

On this page