@design-sdk/figma-url 0.0.53 → 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.
- package/dist/index.d.mts +161 -0
- package/dist/index.d.ts +161 -7
- package/dist/index.js +215 -19
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +194 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +32 -28
- package/dist/access-check.d.ts +0 -8
- package/dist/access-check.js +0 -39
- package/dist/analyze-url.d.ts +0 -26
- package/dist/analyze-url.js +0 -91
- package/dist/compare-url.d.ts +0 -1
- package/dist/compare-url.js +0 -19
- package/dist/constants.d.ts +0 -24
- package/dist/constants.js +0 -30
- package/dist/embed-url.d.ts +0 -20
- package/dist/embed-url.js +0 -56
- package/dist/parse-url.d.ts +0 -23
- package/dist/parse-url.js +0 -70
- package/dist/target-node-config.d.ts +0 -17
- package/dist/target-node-config.js +0 -2
package/dist/parse-url.js
DELETED
|
@@ -1,70 +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
|
-
* e.g. in - "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
|
|
8
|
-
*
|
|
9
|
-
* out - "Y0Gh77AqBoHH7dG1GtK3xF"
|
|
10
|
-
* @param url
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
function parseFileId(url) {
|
|
14
|
-
// this logic is dangerous, but clean and simple. works for now. (think the url format won't change)
|
|
15
|
-
if (url.includes("https://www.figma.com/file/")) {
|
|
16
|
-
return url.split("/")[4];
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
throw `figma file url must contain "https://www.figma.com/file/". the givven was ${url}, which we cannot extract file id from it.`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.parseFileId = parseFileId;
|
|
23
|
-
/**
|
|
24
|
-
* Figma file url's node-id changed over time, this function is to make sure we can handle both formats.
|
|
25
|
-
* to keep `00:00` format
|
|
26
|
-
* @param node_id
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
function formatNodeId(node_id) {
|
|
30
|
-
if (node_id.includes(":") ||
|
|
31
|
-
node_id.includes("%3A") ||
|
|
32
|
-
node_id.includes("-")) {
|
|
33
|
-
// "%3A" is ":" as in url encoding
|
|
34
|
-
if (node_id.includes("%3A")) {
|
|
35
|
-
// decode value, assuming it is url encoded
|
|
36
|
-
node_id = decodeURIComponent(node_id);
|
|
37
|
-
}
|
|
38
|
-
if (node_id.includes("-")) {
|
|
39
|
-
// if id is formatted with `-` instead of `:`, replace it.
|
|
40
|
-
node_id = node_id.split("-").join(":");
|
|
41
|
-
}
|
|
42
|
-
// 2. run regex
|
|
43
|
-
if (node_id.match(/[0-9]+:[0-9]+/) !== null) {
|
|
44
|
-
return node_id;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.formatNodeId = formatNodeId;
|
|
49
|
-
/**
|
|
50
|
-
* pattern is "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
|
|
51
|
-
* @param url
|
|
52
|
-
*/
|
|
53
|
-
function parseFileAndNodeId(url) {
|
|
54
|
-
try {
|
|
55
|
-
const _url = new URL(url);
|
|
56
|
-
const params = new URLSearchParams(_url.search);
|
|
57
|
-
const nodeId = formatNodeId(params.get("node-id"));
|
|
58
|
-
const fileId = parseFileId(url);
|
|
59
|
-
return {
|
|
60
|
-
url: url,
|
|
61
|
-
file: fileId,
|
|
62
|
-
node: nodeId,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch (_) {
|
|
66
|
-
// empty url, invalud url
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
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
|
-
}
|