Skip to main content
Module

x/abstruct/bindings.ts>or

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

Factory for validator composer like Logical OR.

Examples

Example 1

import {
  or,
  type Validator,
} from "https://deno.land/x/abstruct@$VERSION/mod.ts";
import { assertType, type Has } from "https://deno.land/std/testing/types.ts";
declare const v1: Validator;
declare const v2: Validator;
declare const v3: Validator;

const validator = or(v1, v2, v3);

If the validators are not type-compatible with each other, generics must be specified.

Example 2

import {
  or,
  type Validator,
} from "https://deno.land/x/abstruct@$VERSION/mod.ts";
import { assertType, type Has } from "https://deno.land/std/testing/types.ts";
declare const v1: Validator<unknown, string>;
declare const v2: Validator<unknown, number>;
const validator = or<unknown, string | number>(v1, v2);

assertType<Has<typeof validator, Validator<unknown, string | number>>>(true);

For more information, see Specifying Type Arguments.

Type Parameters

optional
In = unknown
optional
RIn extends In = In

Parameters

v1: Readonly<Validator<In, RIn>>
v2: Readonly<Validator<In, RIn>>
...validations: Readonly<Validator<In, RIn>>[]