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

marcomontalbano / figma-export / 7970372673

20 Feb 2024 08:16AM UTC coverage: 96.473% (-0.2%) from 96.693%
7970372673

Pull #157

github

marcomontalbano
deps: update other dependencies to latest
Pull Request #157: Update all dependencies – drop support for Node.js 12 and 14

236 of 258 branches covered (91.47%)

Branch coverage included in aggregate %.

612 of 621 relevant lines covered (98.55%)

17.9 hits per line

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

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

4
import { notNullish } from '../utils';
1✔
5

6
import { parse as parsePaintStyle } from './paintStyle';
1✔
7
import { parse as parseEffectStyle } from './effectStyle';
1✔
8
import { parse as parseTextStyle } from './textStyle';
1✔
9
// import { parse as parseGridStyle } from './gridStyle';
10

11
const fetchStyles = async (
1✔
12
    client: Figma.ClientInterface,
13
    fileId: string,
14
    styles: { readonly [key: string]: Figma.Style },
15
    version?: string,
16
): Promise<FigmaExport.StyleNode[]> => {
18✔
17
    const styleIds = Object.keys(styles);
18✔
18

19
    if (styleIds.length === 0) {
18!
20
        throw new Error('No styles found');
×
21
    }
22

23
    const { data: { nodes } } = await client.fileNodes(fileId, { ids: styleIds, version }).catch((error: Error) => {
18✔
24
        throw new Error(`while fetching fileNodes: ${error.message}`);
1✔
25
    });
26

27
    const styleNodes = Object.values(nodes).map((node) => node?.document);
498!
28

29
    return styleNodes.map((node) => ({
498✔
30
        ...(node ? styles[node.id] : ({} as Figma.Style)),
498!
31
        ...(node as Figma.Node),
32
    }));
33
};
34

35
const parseStyles = (styleNodes: FigmaExport.StyleNode[]): FigmaExport.Style[] => {
1✔
36
    return styleNodes.map((node) => {
15✔
37
        const parsedStyles = undefined
105✔
38
            || parsePaintStyle(node)
39
            || parseEffectStyle(node)
40
            || parseTextStyle(node);
41
            // || parseGridStyle(node)
42

43
        if (!parsedStyles) {
105✔
44
            return undefined;
3✔
45
        }
46

47
        return {
102✔
48
            name: node.name,
49
            comment: node.description,
50
            visible: node.visible !== false,
51
            originalNode: node,
52
            ...parsedStyles,
53
        };
54
    }).filter(notNullish);
55
};
56

57
export {
58
    fetchStyles,
1✔
59
    parseStyles,
1✔
60
};
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