Design Tokens Community Group
These utilities have to do with the Design Tokens W3C Community Group specification.
For converting a ZIP or JSON tokens file to the DTCG format, use the button below:
This button is a tiny Web Component using file input as a wrapper around the convert DTCG utils listed below.
convertToDTCG
This function converts your dictionary object to DTCG formatted dictionary, meaning that your value
, type
and description
properties are converted to be prefixed with $
, and the $type
property is moved from the token level to the topmost common ancestor token group.
applyTypesToGroup
is true
by default, but can be turned off by setting to false
.
dictionary
is the result of doing for example JSON.parse() on your tokens JSON string so it becomes a JavaScript object type.
convertJSONToDTCG
This function converts your JSON (either a JSON Blob or string that is an absolute filepath to your JSON file) to a JSON Blob which has been converted to DTCG format, see convertToDTCG
function above.
applyTypesToGroup
option can be passed, same as for convertToDTCG
function.
Note that if you use a filepath instead of Blob as input, this filepath should preferably be an absolute path.
You can use a utility like node:path
or a browser-compatible copy like path-unified
to resolve path segments or relative paths to absolute ones.
convertZIPToDTCG
This function converts your ZIP (either a ZIP Blob or string that is an absolute filepath to your ZIP file) to a ZIP Blob which has been converted to DTCG format, see convertToDTCG
function above.
Basically the same as convertJSONToDTCG
but for a ZIP file of JSON tokens.
typeDtcgDelegate
This function processes your “Design Tokens Community Group Draft spec”-compliant dictionary of tokens, and ensures that $type
inheritance is applied.
We built this utility because it’s cheaper to apply the inheritance once, rather than on every access of a token’s “$type” property, checking the ancestor tree to find it.
This utility runs by default in Style-Dictionary after the parser hook and before the preprocessor hook.
Input:
Output: