Skip to main content
Module

x/valivar/dist/valivar.esm.js>Schema

Javascript/Typescript schema-based validation and sanitation
Latest
class Schema
import { Schema } from "https://deno.land/x/valivar@v6.2.11/dist/valivar.esm.js";

A Schema defines the structure that objects should be validated against.

Examples

const post = new Schema({ title: { type: String, required: true, length: { min: 1, max: 255 } }, content: { type: String, required: true }, published: { type: Date, required: true }, keywords: [{ type: String }] })

Constructors

new
Schema(obj?, opts?)

Methods

assert(obj, opts)

Assert that given obj is valid.

enforce(obj)

Create errors for all properties that are not defined in the schema

hook(fn)

Accepts a function that is called whenever new props are added.

message(name, message)
path(path, rules)

Create or update path with given rules.

propagate(path, prop)

Notify all subscribers that a property has been added.

strip(obj)

Strip all keys not defined in the schema

Typecast given obj.

typecaster(name, fn)
validate(obj, opts?)

Validate given obj.

validator(name, fn)