A zod-like schema validator, 100% type-safe.
Made for fun and learning purposes.
npm i bodek
The API is basically the same as Zod's, but only with the core functionality (again, learning purposes...)
import { b } from 'bodek'; const schema = b.object({ name: b.string().min(3).max(10), age: b.number().min(18), }); // No errors schema.parse({ name: 'John', age: 30, }); // Throws an error schema.parse({ name: 'John', age: 10, });
import { b } from 'bodek'; const schema = b.object({ name: b.string().min(3).max(10), age: b.number().min(18), }); const { success, data, error } = schema.safeParse({ name: 'John', age: 30, }); if (success) { console.log(data); } else { console.error(error); }
import { b } from 'bodek'; const schema = b.object({ name: b .string() .min(3) .max(10) .refine((name) => name.toLowerCase() !== 'john', 'Name cannot be John'), age: b.number().min(18), }); // Throws an error schema.parse({ name: 'John', age: 30, });