Skip to main content
Module

x/abstruct/mod.ts>defineScalarValidator

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

Create validator from check function.

Examples

Example 1

import { defineScalarValidator } from "https://deno.land/x/abstruct@$VERSION/validators/utils.ts";

const StringValidator = defineScalarValidator<unknown, string>((input) => {
 const typeOf = typeof input;

 return typeOf === "string" || `should be string, actual ${typeOf}`;
});

Type Parameters

optional
In = unknown
optional
RIn extends In = In

Parameters

check: (input: In) => true | string