Skip to main content
Module

x/valita/mod.ts

A typesafe validation & parsing library for TypeScript.
Latest
import * as valita from "https://deno.land/x/valita@v0.3.8/mod.ts";

Examples

Example 1

import * as v from "@badrap/valita";

const vehicle = v.union(
  v.object({ type: v.literal("plane"), airline: v.string() }),
  v.object({ type: v.literal("train") }),
  v.object({ type: v.literal("automobile"), make: v.string() })
);
vehicle.parse({ type: "bike" });
// ValitaError: invalid_literal at .type (expected "plane", "train" or "automobile")

Classes

A validator/parser marked as "optional", signifying that their value can be missing from the parsed object.

c
Type
abstract

A base class for all concreate validators/parsers.

An error type representing one or more validation/parsing errors.

Functions

Create a validator for an array type T[], where T is the output type of the given subvalidator.

Create a validator that matches any bigint value.

Create a validator that matches any boolean value.

Create a value for returning a parsing error from chain().

Create a validator that can reference itself, directly or indirectly.

Create a validator for a specific string, number, bigint or boolean value.

Create a validator that never matches any value, analogous to the TypeScript type never.

Create a validator that matches null.

Create a validator that matches any number value.

Create a validator for an object type.

Create a validator for a record type Record<string, T>, where T is the output type of the given subvalidator.

Create a validator that matches any string value.

Create a validator for an array type [T1, T2, ..., Tn], where T1, T2, ..., Tn are the output types of the given subvalidators.

Create a validator that matches undefined.

Create a validator that matches any type T1 | T2 | ... | Tn, where T1, T2, ..., Tn are the output types of the given subvalidators.

Create a validator that matches any value, analogous to the TypeScript type unknown.

Type Aliases

A validation/parsing failure.

Return the inferred output type of a validator.

A successful validation/parsing result.

A validation/parsing success or failure.