Skip to content

Transforms

Transforms modify taxonomy values when generating event keys. They’re defined as pipelines of steps.

opentp.yaml
spec:
transforms:
slug:
steps:
- step: lower
- step: trim
- step: replace
params:
pattern: " "
with: "_"

Reference transforms in key patterns:

spec:
events:
key:
pattern: "{area | slug}::{event | slug}"

Multiple transforms can be chained:

pattern: "{area | lower | truncate}::{event | slug}"

Converts string to lowercase.

- step: lower
InputOutput
Hello Worldhello world
AUTHauth

Converts string to uppercase.

- step: upper
InputOutput
hello worldHELLO WORLD
authAUTH

Removes leading and trailing whitespace.

- step: trim
InputOutput
hello hello
auth auth

Replaces occurrences of a pattern.

- step: replace
params:
pattern: " "
with: "_"
ParamsInputOutput
pattern: " ", with: "_"hello worldhello_world
pattern: "-", with: "_"my-eventmy_event

Limits string length.

- step: truncate
params:
maxLen: 50
ParamsInputOutput
maxLen: 10hello worldhello worl
maxLen: 5authauth

Converts to snake_case.

- step: to-snake-case
InputOutput
Hello Worldhello_world
helloWorldhello_world
HelloWorldhello_world

Converts to kebab-case.

- step: to-kebab
InputOutput
Hello Worldhello-world
helloWorldhello-world
HelloWorldhello-world

Converts to camelCase.

- step: to-camel-case
InputOutput
hello worldhelloWorld
hello_worldhelloWorld
Hello WorldhelloWorld

Replaces spaces with underscores.

- step: to-underscore
InputOutput
hello worldhello_world
hello worldhello__world

Collapses multiple consecutive characters into one.

- step: collapse
params:
char: "_"
ParamsInputOutput
char: "_"hello___worldhello_world
char: " "hello worldhello world

Keeps only specified characters.

- step: keep
params:
chars: "abcdefghijklmnopqrstuvwxyz0123456789_"
ParamsInputOutput
chars: "a-z0-9"hello-123!hello123

Maps characters to replacements.

- step: transliterate
params:
map:
"ä": "ae"
"ö": "oe"
"ü": "ue"
ParamsInputOutput
map: {"é": "e"}cafécafe
slug:
steps:
- step: lower
- step: trim
- step: replace
params:
pattern: " "
with: "_"
- step: keep
params:
chars: "abcdefghijklmnopqrstuvwxyz0123456789_"
short-id:
steps:
- step: lower
- step: to-snake-case
- step: truncate
params:
maxLen: 30

Create custom transforms in JavaScript:

my-transforms/reverse/index.js
module.exports = {
name: 'reverse',
factory: (params) => (value) => {
return value.split('').reverse().join('');
}
};

Load with CLI:

Terminal window
opentp validate --external-transforms ./my-transforms

Or in config:

opentp.yaml
spec:
external:
transforms: ./my-transforms