Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

StyleShit/bodek

Repository files navigation

Bodek

A zod-like schema validator, 100% type-safe.

Made for fun and learning purposes.

Installation

npm i bodek

Usage

The API is basically the same as Zod's, but only with the core functionality (again, learning purposes...)

parse:

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,
});

safeParse:

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);
}

refine:

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,
});

About

A zod-like schema validator, 100% type-safe

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

AltStyle によって変換されたページ (->オリジナル) /