@primer/primitives
Version:
Typography, spacing, and color primitives for Primer design system
22 lines (21 loc) • 1.03 kB
JavaScript
export const transformNamePathToFigma = (token, options) => {
let pathArray = token.path.filter((part) => part !== '@');
if (['fgColor', 'borderColor', 'bgColor'].includes(pathArray[0]) && pathArray.length === 3) {
pathArray = [pathArray[0], `${pathArray[1]}-${pathArray[2]}`];
}
return ([options === null || options === void 0 ? void 0 : options.prefix, ...pathArray]
// remove undefined if exists
.filter((part) => typeof part === 'string' && part !== '@')
.join('/'));
};
/**
* @description converts the [TransformedToken's](https://github.com/amzn/style-dictionary/blob/main/types/TransformedToken.d.ts) `.path` array to a specific figma name
* @type name transformer — [StyleDictionary.NameTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts)
* @matcher omitted to match all tokens
* @transformer returns `string`
*/
export const namePathToFigma = {
name: 'name/pathToFigma',
type: 'name',
transform: transformNamePathToFigma,
};