diff --git a/.changeset/thirty-spoons-flow.md b/.changeset/thirty-spoons-flow.md new file mode 100644 index 0000000..2751fee --- /dev/null +++ b/.changeset/thirty-spoons-flow.md @@ -0,0 +1,5 @@ +--- +'@tokens-studio/sd-transforms': patch +--- + +Fix fontWeights transformer to allow spaces within fontWeights. diff --git a/src/transformFontWeights.ts b/src/transformFontWeights.ts index 0904e31..03b8281 100644 --- a/src/transformFontWeights.ts +++ b/src/transformFontWeights.ts @@ -1,5 +1,5 @@ export const fontWeightMap = { - hairline: 1, + hairline: 100, thin: 100, extralight: 200, ultralight: 200, @@ -18,13 +18,15 @@ export const fontWeightMap = { bold: 700, dreiviertelfett: 700, extrabold: 800, - ultabold: 800, + ultrabold: 800, fett: 800, black: 900, heavy: 900, super: 900, extrafett: 900, - ultra: 1000, + ultra: 950, + ultrablack: 950, + extrablack: 950, }; export const fontStyles = ['italic', 'oblique', 'normal']; @@ -45,8 +47,9 @@ export function transformFontWeights( const match = `${value}`.match(fontWeightReg); let mapped; + if (match?.groups?.weight) { - mapped = fontWeightMap[match?.groups?.weight.toLowerCase()]; + mapped = fontWeightMap[match?.groups?.weight.replace(/\s/g, '').toLowerCase()]; if (match.groups.style) { mapped = `${mapped} ${match.groups.style.toLowerCase()}`; } diff --git a/test/spec/transformFontWeights.spec.ts b/test/spec/transformFontWeights.spec.ts index c20edfa..dfa0e67 100644 --- a/test/spec/transformFontWeights.spec.ts +++ b/test/spec/transformFontWeights.spec.ts @@ -24,4 +24,9 @@ describe('transform dimension', () => { expect(transformFontWeights('Light normal')).to.equal(`300 normal`); expect(transformFontWeights('ExtraBold Italic')).to.equal(`800 italic`); }); + + it('supports fontWeights with space separators', () => { + expect(transformFontWeights('Extra Bold')).to.equal(800); + expect(transformFontWeights('Ultra Black Italic')).to.equal(`950 italic`); + }); });