@design-sdk/figma-url 0.0.54 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +0,0 @@
1
- import { FigmaTargetNodeConfig } from "./target-node-config";
2
- /**
3
- * extracts file id from share link
4
- *
5
- * Supports multiple Figma URL patterns:
6
- * - Old: "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
7
- * - New: "https://www.figma.com/design/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
8
- * - New: "https://www.figma.com/board/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
9
- * - New: "https://www.figma.com/slides/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
10
- * - New: "https://www.figma.com/site/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
11
- *
12
- * out - "Y0Gh77AqBoHH7dG1GtK3xF"
13
- * @param url
14
- * @returns
15
- */
16
- export declare function parseFileId(url: string): string;
17
- /**
18
- * Figma file url's node-id changed over time, this function is to make sure we can handle both formats.
19
- * to keep `00:00` format
20
- * @param node_id
21
- * @returns
22
- */
23
- export declare function formatNodeId(node_id: string): string;
24
- /**
25
- * pattern examples:
26
- * - "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
27
- * - "https://www.figma.com/design/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
28
- * - "https://www.figma.com/board/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
29
- * - "https://www.figma.com/slides/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
30
- * - "https://www.figma.com/site/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
31
- * @param url
32
- */
33
- export declare function parseFileAndNodeId(url: string): FigmaTargetNodeConfig | undefined;
package/dist/parse-url.js DELETED
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseFileAndNodeId = exports.formatNodeId = exports.parseFileId = void 0;
4
- /**
5
- * extracts file id from share link
6
- *
7
- * Supports multiple Figma URL patterns:
8
- * - Old: "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
9
- * - New: "https://www.figma.com/design/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
10
- * - New: "https://www.figma.com/board/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
11
- * - New: "https://www.figma.com/slides/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
12
- * - New: "https://www.figma.com/site/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
13
- *
14
- * out - "Y0Gh77AqBoHH7dG1GtK3xF"
15
- * @param url
16
- * @returns
17
- */
18
- function parseFileId(url) {
19
- // File ID is in the same position (4th segment) for all URL patterns
20
- const supportedPatterns = [
21
- "https://www.figma.com/file/",
22
- "https://www.figma.com/design/",
23
- "https://www.figma.com/board/",
24
- "https://www.figma.com/slides/",
25
- "https://www.figma.com/site/",
26
- ];
27
- const matchedPattern = supportedPatterns.find((pattern) => url.includes(pattern));
28
- if (matchedPattern) {
29
- return url.split("/")[4];
30
- }
31
- else {
32
- throw `figma url must contain one of the supported patterns (file/, design/, board/, slides/, site/). the given was ${url}, which we cannot extract file id from it.`;
33
- }
34
- }
35
- exports.parseFileId = parseFileId;
36
- /**
37
- * Figma file url's node-id changed over time, this function is to make sure we can handle both formats.
38
- * to keep `00:00` format
39
- * @param node_id
40
- * @returns
41
- */
42
- function formatNodeId(node_id) {
43
- if (node_id.includes(":") ||
44
- node_id.includes("%3A") ||
45
- node_id.includes("-")) {
46
- // "%3A" is ":" as in url encoding
47
- if (node_id.includes("%3A")) {
48
- // decode value, assuming it is url encoded
49
- node_id = decodeURIComponent(node_id);
50
- }
51
- if (node_id.includes("-")) {
52
- // if id is formatted with `-` instead of `:`, replace it.
53
- node_id = node_id.split("-").join(":");
54
- }
55
- // 2. run regex
56
- if (node_id.match(/[0-9]+:[0-9]+/) !== null) {
57
- return node_id;
58
- }
59
- }
60
- }
61
- exports.formatNodeId = formatNodeId;
62
- /**
63
- * pattern examples:
64
- * - "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
65
- * - "https://www.figma.com/design/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
66
- * - "https://www.figma.com/board/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
67
- * - "https://www.figma.com/slides/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
68
- * - "https://www.figma.com/site/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
69
- * @param url
70
- */
71
- function parseFileAndNodeId(url) {
72
- try {
73
- const _url = new URL(url);
74
- const params = new URLSearchParams(_url.search);
75
- const nodeId = formatNodeId(params.get("node-id"));
76
- const fileId = parseFileId(url);
77
- return {
78
- url: url,
79
- file: fileId,
80
- node: nodeId,
81
- };
82
- }
83
- catch (_) {
84
- // empty url, invalud url
85
- return;
86
- }
87
- }
88
- exports.parseFileAndNodeId = parseFileAndNodeId;
@@ -1,17 +0,0 @@
1
- /**
2
- * target node configuration for figma node that contains all fileid, nodeid and the figma url of the target.
3
- */
4
- export interface FigmaTargetNodeConfig {
5
- /**
6
- * url of target node originated from figma
7
- */
8
- url: string;
9
- /**
10
- * id of the file originated from figma
11
- */
12
- file: string;
13
- /**
14
- * id of the node originated from figma
15
- */
16
- node: string;
17
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });