check
Creates a check validation action.
const Action = v.check<TInput, TMessage>(requirement, message);
Generics
TInputextends anyTMessageextends ErrorMessage<CheckIssue<TInput>> | undefined
Parameters
requirement(input: TInput) => booleanmessageTMessage
Explanation
With check you can freely validate the input and return true if it is valid or false otherwise. If the input does not match your requirement, you can use message to customize the error message.
Returns
ActionCheckAction<TInput, TMessage>
Examples
The following examples show how check can be used.
Check object properties
Schema to check the properties of an object.
const CustomObjectSchema = v.pipe(
v.object({
list: v.array(v.string()),
length: v.number(),
}),
v.check(
(input) => input.list.length === input.length,
'The list does not match the length.'
)
);
Related
The following APIs can be combined with check.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/check/