• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marcomontalbano / figma-export / 4952563450

pending completion
4952563450

Pull #145

github

GitHub
Merge f9fadd50b into e7ae576aa
Pull Request #145: Add `output-styles-as-style-dictionary` package

211 of 231 branches covered (91.34%)

Branch coverage included in aggregate %.

60 of 60 new or added lines in 2 files covered. (100.0%)

561 of 566 relevant lines covered (99.12%)

58.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/packages/core/src/lib/figmaStyles/textStyle.ts
1
import * as Figma from 'figma-js';
2
import * as FigmaExport from '@figma-export/types';
3

4
const translateTextTransform = (figmaTextCase?: string): FigmaExport.TextTransform => {
1✔
5
    const map: { [key: string]: FigmaExport.TextTransform } = {
13✔
6
        undefined: 'none',
7
        UPPER: 'uppercase',
8
        LOWER: 'lowercase',
9
        TITLE: 'capitalize',
10
    };
11

12
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13
    return map[figmaTextCase!] || map.undefined;
13✔
14
};
15

16
const translateFontVariant = (figmaTextCase?: string): FigmaExport.FontVariant => {
1✔
17
    const map: { [key: string]: FigmaExport.FontVariant } = {
13✔
18
        undefined: 'normal',
19
        SMALL_CAPS: 'small-caps',
20
        SMALL_CAPS_FORCED: 'all-small-caps',
21
    };
22

23
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24
    return map[figmaTextCase!] || map.undefined;
13✔
25
};
26

27
const translateTextDecoration = (figmaTextDecoration?: string): FigmaExport.TextDecoration => {
1✔
28
    const map: { [key: string]: FigmaExport.TextDecoration } = {
13✔
29
        undefined: 'none',
30
        STRIKETHROUGH: 'line-through',
31
        UNDERLINE: 'underline',
32
    };
33

34
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
35
    return map[figmaTextDecoration!] || map.undefined;
13!
36
};
37

38
const translateTextAlign = (figmaTextAlignHorizontal: string): FigmaExport.TextAlign => {
1✔
39
    const map: { [key: string]: FigmaExport.TextAlign } = {
13✔
40
        LEFT: 'left',
41
        RIGHT: 'right',
42
        CENTER: 'center',
43
        JUSTIFIED: 'justify',
44
    };
45

46
    return map[figmaTextAlignHorizontal];
13✔
47
};
48

49
const translateVerticalAlign = (figmaTextAlignVertical: string): FigmaExport.VerticalAlign => {
1✔
50
    const map: { [key: string]: FigmaExport.VerticalAlign } = {
13✔
51
        TOP: 'top',
52
        CENTER: 'middle',
53
        BOTTOM: 'bottom',
54
    };
55

56
    return map[figmaTextAlignVertical];
13✔
57
};
58

59
const createTextStyle = (textNode: Figma.Style & Figma.Text): FigmaExport.TextStyle => {
1✔
60
    const {
61
        fontFamily, fontWeight, fontSize, lineHeightPx, letterSpacing,
62
        italic, textCase, textDecoration, textAlignHorizontal, textAlignVertical,
63
    } = textNode.style;
13✔
64

65
    return {
13✔
66
        fontFamily,
67
        fontWeight,
68
        fontSize,
69
        letterSpacing,
70
        lineHeight: lineHeightPx,
71
        fontStyle: italic ? 'italic' : 'normal',
13!
72
        fontVariant: translateFontVariant(textCase),
73
        textTransform: translateTextTransform(textCase),
74
        textDecoration: translateTextDecoration(textDecoration),
75
        textAlign: translateTextAlign(textAlignHorizontal),
76
        verticalAlign: translateVerticalAlign(textAlignVertical),
77
    };
78
};
79

80
const parse = (node: FigmaExport.StyleNode): FigmaExport.StyleTypeText | undefined => {
1✔
81
    if (node.styleType === 'TEXT' && node.type === 'TEXT') {
16✔
82
        return {
13✔
83
            styleType: 'TEXT',
84
            style: createTextStyle(node),
85
        };
86
    }
87

88
    return undefined;
3✔
89
};
90

91
export {
92
    parse,
1✔
93
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc