custom

Creates a custom pipeline validation action.

const Validation = custom<TInput>(requirement, message);

Generics

  • TInput extends string

Parameters

  • requirement (input: TInput) => boolean
  • message ErrorMessage | undefined

Explanation

With custom 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 custom can be used.

Custom object schema

Schema to validate a custom object.

const CustomObjectSchema = object(
  {
    list: array(string()),
    length: number(),
  },
  [
    custom(
      (input) => input.list.length === input.length,
      'The list does not match the length.'
    ),
  ]
);

The following APIs can be combined with custom.

Schemas

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 dailydotdev
  • GitHub profile picture of ivan-mihalic
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper