Tokens
These utilities have to do with processing/formatting tokens.
flattenTokens Deprecated
Deprecated in favor of
convertTokenData
, see below.
Flatten dictionary tokens object to an array of flattened tokens.
The key is added so that it is easy to transform the flattened array back to a nested object if needed later, by using the convertTokenData utility.
convertTokenData
Convert tokens from one data structure to another.
Available data structures:
Array
(available asallTokens
ondictionary
) -> easy to iterate e.g. for outputting flat formatsObject
(available astokens
ondictionary
) -> similar to JSON input format e.g. DTCG format, useful for outputting nested / deep formats such as JSONMap
(available astokenMap
ondictionary
) -> easy to iterate & access, optimal for token processing and will be used internally in Style Dictionary in the future
All 3 structures can be converted to one another
Param | Type | Description |
---|---|---|
tokens | Tokens | Token[] | TokenMap | The input tokens data as either Object , Array or Map . |
options | Object | Options object, with multiple properties. |
options.usesDtcg | boolean | Whether the input data uses DTCG syntax, false by default. |
options.output | 'object' | 'array' | 'map' | Output data format |
We are currently considering making the Map
structure the de-facto standard in a future v5, making the Object
/Array
versions available only through this utility. This is to optimize the library’s base functionality.
This utility auto-detects the input data type and allows you to specify the desired output data type.
You can optionally pass usesDtcg
flag as well if you use DTCG format, this is necessary for converting from Object to Map
/Array
, since we need to know whether to use the $value
or value
to identify tokens in the Object
.
stripMeta
Allows you to strip meta data from design tokens, useful if you want to output clean nested formats.
You can define which meta properties to strip or which properties to keep (allowlist / blocklist), in the second options
parameter.
This utility is also used in the 'json'
format.