Spec-Zone.ru › Valibot

check

Creates a check validation action.

const Action = v.check<TInput, TMessage>(requirement, message);

Generics

  • TInput extends any
  • TMessage extends ErrorMessage<CheckIssue<TInput>> | undefined

Parameters

  • requirement (input: TInput) => boolean
  • message TMessage

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

  • Action CheckAction<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

forward, pipe

Utils

isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/check/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API