Skip to main content
Module

x/abstruct/mod.ts>assert

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

Assert that the input passes validator.

Examples

Example 1

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

const Profile = object({ 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
A extends In = In

Parameters

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

Returns

asserts input is A