The following type-validations provide validations for all JavaScript's primitive types.
| Type validation | Validated type | Remarks |
|---|---|---|
string |
string |
|
number |
number |
|
boolean |
boolean |
|
nullValidation |
null |
|
undefinedValidation |
undefined |
|
symbol |
symbol |
|
bigint |
bigint |
|
any |
any |
Always returns true. |
unknown |
unknown |
Always returns true. Alias of any. |
never |
never |
Always returns false. |
maybeString |
string | undefined |
|
maybeNumber |
number | undefined |
|
maybeBoolean |
boolean | undefined |
|
nullOrUndefined |
null | undefined |
|
maybeSymbol |
symbol | undefined |
|
maybeBigint |
bigint | undefined |
The following assertions provide assertions for all JavaScript's primitive types.
Each assertion function creates a corresponding assertion provided errFactory function.
A function that creates an error for a given value and rejections.
Type: (val: unknown, rejections: ValidationRejection[]) => unknown
| Assertion factory | Validated type | Remarks |
|---|---|---|
stringAssertion |
string |
|
numberAssertion |
number |
|
booleanAssertion |
boolean |
|
nullAssertion |
null |
|
undefinedAssertion |
undefined |
|
symbolAssertion |
symbol |
|
bigintAssertion |
bigint |
|
anyAssertion |
any |
Returns an assertion that always returns. |
unknownAssertion |
unknown |
Returns an assertion that always returns. Alias of anyAssertion. |
assert |
never |
Returns an assertion that always throws. |
maybeStringAssertion |
string | undefined |
|
maybeNumberAssertion |
number | undefined |
|
maybeBooleanAssertion |
boolean | undefined |
|
nullOrUndefinedAssertion |
null | undefined |
|
maybeSymbolAssertion |
symbol | undefined |
|
maybeBigintAssertion |
bigint | undefined |