Skip to main content
This release is 3 versions behind 0.4.4 — the latest version of @oridune/validator. Jump to latest

Oridune validator is a TypeScript-first schema declaration and validation library like Zod.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
41%
Published
a week ago (0.4.1)
class BaseValidator

Constructors

new
BaseValidator(
ID: string,
ValidatorOptions?: TBaseValidatorOptions,
)

Type Parameters

Shape = any
Input = any
Output = any

Properties

protected
CustomValidators: TCustomValidator<unknown, unknown, unknown>[]
protected
abstract
Description: string
protected
abstract
Sample: any
protected
abstract
_memory: Record<string, any>

Methods

protected
_cast(_ctx: IValidatorContext<unknown, unknown>): Promise<void> | void
protected
_custom<Return>(
validator: TCustomValidator<any, any, Return>,
isDefault?: boolean,
)
protected
_isPlainObject(value: any)
protected
_memo<T>(
keys: string | string[],
callback: () => T,
): T

Adds a stop point to the validation if there was an error occured on the current validator.

custom<Return>(validator: TCustomValidator<Input, Output, Return>)

Provide a custom method for validation.

describe(description: string)

Add a description for the JSON schema.

Get default validator options

sample(sample: any)

Add a sample for the Sample data.

Change the validator's default options

test(
input?: any,
)

Tries to execute the validation chain and returns a boolean value based on the result.

Adds a stop point to the validation if there was an error occured on the current validator.

Generates a JSON schema based on your validation schema.

Generates a Sample data based on your validation schema.

Converts the runtime context into a static validator.

try(
input?: any,
)

Tries to execute the validation chain and if there is an error, it will not be thrown but instead will be returned.

Executes the validation chain.

Static Methods

createFactory<
T,
A extends unknown[],
>
(cls: new (...args: A) => T): (...args: A) => T
resolveErrorMessage(
message: TErrorMessage | undefined,
defaultMessage: string,
)
resolveValidator<V extends BaseValidator>(validator: any): V
resolveValidator<V extends BaseValidator>(
validator: any,
silent: false,
): V
resolveValidator<V extends BaseValidator>(
validator: any,
silent: true,
): V | null

Add Package

deno add jsr:@oridune/validator

Import symbol

import { BaseValidator } from "@oridune/validator";

---- OR ----

Import directly with a jsr specifier

import { BaseValidator } from "jsr:@oridune/validator";

Add Package

npx jsr add @oridune/validator

Import symbol

import { BaseValidator } from "@oridune/validator";

Add Package

yarn dlx jsr add @oridune/validator

Import symbol

import { BaseValidator } from "@oridune/validator";

Add Package

pnpm dlx jsr add @oridune/validator

Import symbol

import { BaseValidator } from "@oridune/validator";

Add Package

bunx jsr add @oridune/validator

Import symbol

import { BaseValidator } from "@oridune/validator";