import { NumberAsserter } from "https://deno.land/x/typeguardkit@0.33.0/mod.ts";
A NumberAsserter
is an Asserter<number>
, with any additional constraints
defined by its NumberAsserterOptions
properties.
The rules
option can be used to specify validate
functions and their
requirements
. Each validate
function should return true
if value
is
valid according to the rule, and false
otherwise. requirements
must not
be empty or contain any blank string
s.
The provided NumberAsserterOptions
are made accessible as properties of the
created NumberAsserter
.
A NumberAsserter
is also a Validator<number>
with a validate
method,
which checks only that the provided value
meets any constraints defined in
the NumberAsserterOptions
, and returns any issues. This can be used to
validate user input client side, where it should already be known that
value
is a number
.
Example:
import { Asserted, NumberAsserter } from "typeguardkit";
export const _EvenNumberInRange = new NumberAsserter("EvenNumberInRange", {
min: { value: 0, inclusive: true },
max: { value: 100, inclusive: true },
step: 2,
});
export type EvenNumberInRange = Asserted<typeof _EvenNumberInRange>;