Skip to main content

Transformers

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

import type { Transformer } from 'dynamodb-toolbox/transformers/prefix'

const PREFIX = 'POKEMON#'

const prefix: Transformer<string, string> = {
// Updates the value during parsing
parse: input => [PREFIX, input].join(''),
// Updates the value back during formatting
format: saved => 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 🤗