Skip to content

Commit

Permalink
fix: fontWeights allow spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed Feb 1, 2024
1 parent 9259f54 commit 2521528
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-spoons-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokens-studio/sd-transforms': patch
---

Fix fontWeights transformer to allow spaces within fontWeights.
11 changes: 7 additions & 4 deletions src/transformFontWeights.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const fontWeightMap = {
hairline: 1,
hairline: 100,
thin: 100,
extralight: 200,
ultralight: 200,
Expand All @@ -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'];
Expand All @@ -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()}`;
}
Expand Down
5 changes: 5 additions & 0 deletions test/spec/transformFontWeights.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
});
});

0 comments on commit 2521528

Please sign in to comment.