@knownasrazi/isval
v1.0.0
Published
Composable runtime type validators with TypeScript inference to validate before you trust.
Maintainers
Readme
isval
Composable runtime validators with inference.
Zero dependencies - ~2 KB gzipped - TypeScript - Node + Bun + browser
Install
bun add @knownasrazi/isval
npm install @knownasrazi/isvalUsage
import { string, number, boolean, array, object } from "@knownasrazi/isval";
const schema = object({
name: string(),
age: number(),
tags: array(string()),
});
schema.parse({ name: "razi", age: 30, tags: ["a"] });
schema.safeParse({ name: 1 }); // { ok: false, errors: [...] }
array(number()).parse([1, 2, 3]);
string().safeParse(5); // { ok: false, errors: ["expected string"] }API
| Export | Description |
| --- | --- |
| string() | Validator<string> |
| number() | Validator<number> (rejects NaN) |
| boolean() | Validator<boolean> |
| array(el) | Validator<T[]> |
| object(schema) | Validator<{ ... }> with inferred output |
Each exposes parse(value): T (throws TypeError) and safeParse(value): { ok, value|errors }.
Development
git clone https://github.com/knownasrazi/isval.git
cd isval
bun install
bun test
bun run build
bun run lintLicense
isval - validate before you trust.
