Transforms
Transforms
Section titled “Transforms”Transforms modify taxonomy values when generating event keys. They’re defined as pipelines of steps.
Defining Transforms
Section titled “Defining Transforms”spec: transforms: slug: steps: - step: lower - step: trim - step: replace params: pattern: " " with: "_"Using Transforms
Section titled “Using Transforms”Reference transforms in key patterns:
spec: events: key: pattern: "{area | slug}::{event | slug}"Multiple transforms can be chained:
pattern: "{area | lower | truncate}::{event | slug}"Built-in Transforms
Section titled “Built-in Transforms”Converts string to lowercase.
- step: lower| Input | Output |
|---|---|
Hello World | hello world |
AUTH | auth |
Converts string to uppercase.
- step: upper| Input | Output |
|---|---|
hello world | HELLO WORLD |
auth | AUTH |
Removes leading and trailing whitespace.
- step: trim| Input | Output |
|---|---|
hello | hello |
auth | auth |
replace
Section titled “replace”Replaces occurrences of a pattern.
- step: replace params: pattern: " " with: "_"| Params | Input | Output |
|---|---|---|
pattern: " ", with: "_" | hello world | hello_world |
pattern: "-", with: "_" | my-event | my_event |
truncate
Section titled “truncate”Limits string length.
- step: truncate params: maxLen: 50| Params | Input | Output |
|---|---|---|
maxLen: 10 | hello world | hello worl |
maxLen: 5 | auth | auth |
to-snake-case
Section titled “to-snake-case”Converts to snake_case.
- step: to-snake-case| Input | Output |
|---|---|
Hello World | hello_world |
helloWorld | hello_world |
HelloWorld | hello_world |
to-kebab
Section titled “to-kebab”Converts to kebab-case.
- step: to-kebab| Input | Output |
|---|---|
Hello World | hello-world |
helloWorld | hello-world |
HelloWorld | hello-world |
to-camel-case
Section titled “to-camel-case”Converts to camelCase.
- step: to-camel-case| Input | Output |
|---|---|
hello world | helloWorld |
hello_world | helloWorld |
Hello World | helloWorld |
to-underscore
Section titled “to-underscore”Replaces spaces with underscores.
- step: to-underscore| Input | Output |
|---|---|
hello world | hello_world |
hello world | hello__world |
collapse
Section titled “collapse”Collapses multiple consecutive characters into one.
- step: collapse params: char: "_"| Params | Input | Output |
|---|---|---|
char: "_" | hello___world | hello_world |
char: " " | hello world | hello world |
Keeps only specified characters.
- step: keep params: chars: "abcdefghijklmnopqrstuvwxyz0123456789_"| Params | Input | Output |
|---|---|---|
chars: "a-z0-9" | hello-123! | hello123 |
transliterate
Section titled “transliterate”Maps characters to replacements.
- step: transliterate params: map: "ä": "ae" "ö": "oe" "ü": "ue"| Params | Input | Output |
|---|---|---|
map: {"é": "e"} | café | cafe |
Common Pipelines
Section titled “Common Pipelines”URL-safe slug
Section titled “URL-safe slug”slug: steps: - step: lower - step: trim - step: replace params: pattern: " " with: "_" - step: keep params: chars: "abcdefghijklmnopqrstuvwxyz0123456789_"Truncated identifier
Section titled “Truncated identifier”short-id: steps: - step: lower - step: to-snake-case - step: truncate params: maxLen: 30Custom Transforms
Section titled “Custom Transforms”Create custom transforms in JavaScript:
module.exports = { name: 'reverse', factory: (params) => (value) => { return value.split('').reverse().join(''); }};Load with CLI:
opentp validate --external-transforms ./my-transformsOr in config:
spec: external: transforms: ./my-transforms