This is an optional object that can be used to customize the output
const options = {
unit: 'px',
transform: (key, value) => {
* // Skip tokens with unknown CSS properties
* if (key.includes('unknown-css-property')) {
* return null;
* }
*
* // Change the value of all font-family tokens to Roboto
* if (key.includes('font-family')) {
* return { key, value: 'Roboto' };
* }
*
* // Return the original token
* return { key, value };
},
};
const tokensConverter = new TokensConverter(options);
const result = tokensConverter.toCssVariables(tokensObj);
Private optionsPrivate formatPrivate formatPrivate formatPrivate formatPrivate processPrivate processPrivate processPrivate processPrivate sanitizeThe object (key and value) containing the tokens
const tokensObj = {
colors: {
primary: '#000',
secondary: '#fff',
},
fontSizes: {
small: '12px',
medium: '16px',
large: '20px',
},
spacing: {
small: '8px',
medium: '16px',
large: '24px',
},
};
Private tokens
This class is used to convert a tokens object into CSS variables.