checkAsync

Creates a check validation action.

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

Generics

Parameters

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

Explanation

With checkAsync 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

Examples

The following examples show how checkAsync can be used.

Cart item schema

Schema to check a cart item object.

import { getProductItem } from '~/api';

const CartItemSchema = v.pipeAsync(
  v.object({
    itemId: v.pipe(v.string(), v.regex(/^[a-z0-9]{10}$/i)),
    quantity: v.pipe(v.number(), v.minValue(1)),
  }),
  v.checkAsync(async (input) => {
    const productItem = await getProductItem(input.itemId);
    return productItem?.quantity >= input.quantity;
  }, 'The required quantity is greater than available.')
);

The following APIs can be combined with checkAsync.

Schemas

Utils

Async

Contributors

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

  • GitHub profile picture of fabian-hiller
  • 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 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 fabulousgk
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of isoden
  • GitHub profile picture of nickytonline
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin