
Valibot Has a Free API You're Not Using
Valibot is a schema validation library that's 98% smaller than Zod. At just 0.5KB minified, it's the lightest validation library with full TypeScript inference. Why Valibot over Zod? Zod: 13.5KB minified (monolithic) Valibot: 0.5-5KB (tree-shakeable — you only ship what you use) The Free APIs You're Missing 1. Modular Design — Import Only What You Need import { object , string , number , email , minLength , parse } from " valibot " ; const UserSchema = object ({ name : string ([ minLength ( 2 )]), email : string ([ email ()]), age : number (), }); const user = parse ( UserSchema , data ); // Only the functions you import end up in your bundle 2. pipe() — Composable Validation Pipelines import { pipe , string , transform , regex , toLowerCase , trim } from " valibot " ; const Slug = pipe ( string (), trim (), toLowerCase (), regex ( /^ [ a-z0-9- ] +$/ ), ); const Price = pipe ( string (), transform (( s ) => parseFloat ( s )), number (), minValue ( 0 ), ); 3. variant() — Discriminated U
Continue reading on Dev.to Webdev
Opens in a new tab


