checkItems
Creates a check items validation action.
const Action = v.checkItems<TInput, TMessage>(requirement, message);
Generics
TInputextends ArrayInputTMessageextends ErrorMessage<CheckItemsIssue<TInput>> | undefined
Parameters
requirementArrayRequirement<TInput>messageTMessage
Explanation
With checkItems you can freely validate the items of an array and return true if they are valid or false otherwise. If an item does not match your requirement, you can use message to customize the error message.
The special thing about
checkItemsis that it automatically forwards each issue to the appropriate item.
Returns
ActionCheckItemsAction<TInput, TMessage>
Examples
The following examples show how checkItems can be used.
No duplicate items
Schema to validate that an array has no duplicate items.
const ArraySchema = v.pipe(
v.array(v.string()),
v.checkItems(
(item, index, array) => array.indexOf(item) === index,
'Duplicate items are not allowed.'
)
);
Related
The following APIs can be combined with checkItems.
Schemas
any, array, custom, instance, tuple, unknown
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/checkItems/