Basic usage

Let's see how the validator works!

As mentioned in the getting started page Oridune validator is mostly similar to Zod. You compose smaller chunks of validators into a validations schema. See the following example:

Create a simple validator

import e from "validator"; // validator maps to https://jsr.io/@oridune/validator

// Define a string validator
const Str = e.string();

// Validation
await Str.validate("foo"); // returns "foo"
await Str.validate(123); // throws ValidationException

// Safe Validation (doesn't throw an error if validation fails)
await Str.try("foo"); // returns { output: "foo", error: null }
await Str.try(123); // returns { output: null, error: ValidationException }

// Boolean Validation
await Str.test("foo"); // returns true
await Str.test(123); // returns false

Create an object Schema

Transform using a Custom validator

Last updated

Was this helpful?