checkItems

Creates a check items validation action.

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

Generics

Parameters

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 checkItems is that it automatically forwards each issue to the appropriate item.

Returns

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.'
  )
);

The following APIs can be combined with checkItems.

Schemas

Methods

Utils

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of Unique-Pixels
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of nickytonline
  • GitHub profile picture of KubaJastrz
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of dslatkin