style-dictionary-utils
Version:
Utilities to use in your style dictionary config
17 lines (16 loc) • 566 B
JavaScript
/**
* getValue
* @description Returns the value of the design token, either token.value or token.$value
* @param token StyleDictionary.DesignToken
* @returns token value
*/
export const getValue = (token, original = undefined) => {
const value = original === 'original' ? token.original.$value : token.$value;
if (token === undefined) {
throw new Error(`The token is undefined.`);
}
if (value === undefined || value === null) {
throw new Error(`The token ${token.name} has no valid $value property.`);
}
return value;
};