@tokens-studio/sd-transforms
Version:
Custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio
27 lines (26 loc) • 812 B
JavaScript
import { percentageToDecimal } from './utils/percentageToDecimal.js';
/**
* Helper: Transforms line-height % to unit-less decimal value
* @example
* 150% -> 1.5
*/
export function transformLineHeight(token) {
const val = token.$value ?? token.value;
const type = token.$type ?? token.type;
if (val === undefined)
return undefined;
const transformLH = (lineHeight) => {
const decimal = percentageToDecimal(lineHeight);
return typeof decimal === 'string' || isNaN(decimal) ? `${lineHeight}` : decimal;
};
if (type === 'typography') {
if (val.lineHeight !== undefined) {
return {
...val,
lineHeight: transformLH(val.lineHeight),
};
}
return val;
}
return transformLH(val);
}