checkItemsAsync

Creates a check items validation action.

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

Generics

Parameters

Explanation

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

Returns

Examples

The following examples show how checkItemsAsync can be used.

Cart items schema

Schema to check an array of cart item objects.

import { getProductItem } from '~/api';

const CartItemsSchema = v.pipeAsync(
  v.array(
    v.object({
      itemId: v.pipe(v.string(), v.uuid()),
      quantity: v.pipe(v.number(), v.minValue(1)),
    })
  ),
  v.checkItemsAsync(async (input) => {
    const productItem = await getProductItem(input.itemId);
    return (productItem?.quantity ?? 0) >= input.quantity;
  }, 'The required quantity is greater than available.')
);

The following APIs can be combined with checkItemsAsync.

Schemas

Utils

Async

Contributors

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

  • GitHub profile picture of EltonLobo07

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 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 fabulousgk
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of andrew-d-jackson
  • GitHub profile picture of dslatkin