Skip to main content
Module

x/abstruct/validation.ts>assert

Abstract structure for JavaScript data validation
Latest
function assert
import { assert } from "https://deno.land/x/abstruct@1.0.0/validation.ts";

Assert that the input passes validator.

Examples

Example 1

import {
 assert,
 number,
 props,
 string,
 ValidationError,
} from "https://deno.land/x/abstruct@$VERSION/mod.ts";
import {
 assertEquals,
 assertIsError,
} from "https://deno.land/std/testing/asserts.ts";

const Profile = props({ name: string, age: number });

try {
 assert(Profile, { name: null, age: null });
} catch (e) {
 assertIsError(e, ValidationError, "<string validation message>");
}

Type Parameters

optional
In = unknown
optional
RIn extends In = In

Parameters

validator: Readonly<Validator<In, RIn>>
input: In
optional
options: Readonly<SingleAssertOptions | MultiAssertOptions> = [UNSUPPORTED]

Returns

asserts input is RIn