@tokens-studio/sd-transforms
Version:
Custom transforms for Style-Dictionary, to work with Design Tokens that are exported from Tokens Studio
20 lines (19 loc) • 581 B
JavaScript
// @ts-expect-error untyped library...
import deepmerge from '@bundled-es-modules/deepmerge';
export function excludeParentKeys(dictionary, transformOpts) {
if (!transformOpts?.excludeParentKeys) {
return dictionary;
}
const copy = {};
Object.values(dictionary).forEach(set => {
Object.entries(set).forEach(([key, tokenGroup]) => {
if (copy[key]) {
copy[key] = deepmerge(copy[key], tokenGroup);
}
else {
copy[key] = tokenGroup;
}
});
});
return copy;
}