A transform normalises a value as it passes through. Declare them on a field, a type or a trait, and
they run in the order written.
fields:
- name: email
type: string
transforms:
- type: trim
- type: lowercase
Every transform takes an optional params map. A transform that cannot handle the value it is
given returns it unchanged rather than failing — a numeric transform on a string leaves the
string alone. That keeps one bad row from failing a whole write, and it means a transform that
silently does nothing is usually a type mismatch.
Regular-expression replace. An uncompilable pattern leaves the value unchanged
truncate
length, ellipsis
Cuts to length; ellipsis: true appends …
pad_left
length, char
Pads to length
pad_right
length, char
Pads to length
strip_html
—
Removes tags, keeps text
mask_partial
start, end, char
Keeps start leading and end trailing characters, masks the middle
mask_partial is the one to reach for on a stored identifier you still need to recognise —
4111********1111. For hiding a value from a reader rather than changing it, use the
mask compliance instead: a transform rewrites
what is stored, a compliance governs who sees it.
Use this when nothing above fits. Anything you would write more than twice belongs in a shared
type or trait rather than repeated inline — see Types and
Traits.
Prefer the highest level that is still true. A lowercase on an email type is applied everywhere
an email exists; the same transform copied onto nine fields is eight chances to forget the tenth.