transform

Creates a custom transformation action.

const Action = transform<TInput, TOutput>(action);

Generics

  • TInput extends any
  • TOutput extends any

Parameters

  • action (input: TInput) => TOutput

Explanation

transform can be used to freely transform the input. The action parameter is a function that takes the input and returns the transformed output.

Returns

Examples

The following examples show how transform can be used.

Transform to length

Schema that transforms a string to its length.

const StringLengthSchema = v.pipe(
  v.string(),
  v.transform((input) => input.length)
);

Add object entry

Schema that transforms an object to add an entry.

const UserSchema = v.pipe(
  v.object({ name: v.string(), age: v.number() }),
  v.transform((input) => ({
    ...input,
    created: new Date().toISOString(),
  }))
);

The following APIs can be combined with transform.

Schemas

Methods

Contributors

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

  • GitHub profile picture of fabian-hiller
  • GitHub profile picture of HJGreen

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 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
  • GitHub profile picture of seahindeniz