pipe

Adds a pipeline to a schema, that can validate and transform its input.

const Schema = v.pipe<TSchema, TItems>(schema, ...items);

Generics

Parameters

  • schema TSchema
  • items TItems

Explanation

pipe creates a modified copy of the given schema, containing a pipeline for detailed validations and transformations. It passes the input data synchronously through the items in the order they are provided and each item can examine and modify it.

Since pipe returns a schema that can be used as the first argument of another pipeline, it is possible to nest multiple pipe calls to extend the validation and transformation further.

Returns

Examples

The following examples show how pipe can be used. Please see the pipeline guide for more examples and explanations.

Email schema

Schema to validate an email.

const EmailSchema = v.pipe(
  v.string(),
  v.nonEmpty('Please enter your email.'),
  v.email('The email is badly formatted.'),
  v.maxLength(30, 'Your email is too long.')
);

String to number

Schema to convert a string to a number.

const NumberSchema = v.pipe(v.string(), v.transform(Number), v.number());

The following APIs can be combined with pipe.

Schemas

Methods

Actions

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