New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

bodek

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bodek

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

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 18 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts