Sometimes the data coming from the design data model is not in a format you'd like it to have. For example, you want the uppercased name of the token, but the data model only provides a real name. For this situation, it is also possible to change attributes using transformers. Transformers take an input value, run it through transformation, and retrieve the result. You use them through dot notation:
{{ name.uppercased() }} // Name = "primary"
Producing this expected output when used:
PRIMARY
Transformers can also be chained, like this:
{{ name.uppercased().prefixed("--")}}
Which will transform the value using all transformers from left to right, producing:
--PRIMARY
There are a plethora of transformers available for each supported data type. Note that transformers can only be used on the data type they are listed under. For example, uppercased() can only be used on string values while random() can be used on arrays.
String Transformers
The following string transformers are available:
- lowercased
- uppercased
- prefixed
- suffixed
- extended
- capitalized
- snakecased
- camelcased
- replacing
- contains
- trimming
- trimmingSpaces
- slashNewlines
- slashSingleQuotes
- slashDoubleQuotes
- split
- splitExpr
- splitNewlines
- substring
- default
- count
- formatDate
- startsWith
- endsWith
Array Transformers
The following array transformers are available:
Object Transformers
The following object transformers are available:
Numeric Transformers
The following numeric transformers are available:
- addedBy
- subtractedBy
- multlipliedBy
- dividedBy
- rounded
- floored
- ceiled
- absolute
- positive
- negative
- formatDate
Support Transformers
Support transformers are special because can be used on any data type. Following support transformers are available: