Skip to main content

Transformers

Transformers allow modifying a primitive attribute value during the transformation step:

const PREFIX = 'POKEMON#'

const prefix = {
// Updates the value during parsing
parse: (input: string) => [PREFIX, input].join(''),
// Updates the value back during formatting
format: (saved: string) => saved.slice(PREFIX.length)
}

// Saves the prefixed value
const pokemonIdSchema = string().transform(prefix)
const pokemonIdSchema = string({ transform: prefix })

For the moment, there's only one available off-the-shelf transformer, but we hope there will be more in the future:

  • prefix: Prefixes a string value

If you think of a transformer that you'd like to see open-sourced, feel free to open an issue or submit a PR 🤗