@design-sdk/figma-url 0.0.42 → 0.0.46
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/analyze-url.js +3 -11
- package/dist/parse-url.d.ts +7 -0
- package/dist/parse-url.js +28 -2
- package/package.json +2 -3
package/dist/analyze-url.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.analyze = exports.FigmaFileOrNodeIdType = exports.FigmaUrlType = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
const parse_url_1 = require("./parse-url");
|
|
5
6
|
var FigmaUrlType;
|
|
6
7
|
(function (FigmaUrlType) {
|
|
7
8
|
/**
|
|
@@ -42,17 +43,8 @@ function analyze(url) {
|
|
|
42
43
|
catch (_) {
|
|
43
44
|
const maybeidlike = url;
|
|
44
45
|
if (maybeidlike.length > 0) {
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
// "%3A" is ":" as in url encoding
|
|
48
|
-
if (_target.includes("%3A")) {
|
|
49
|
-
// decode value, assuming it is url encoded
|
|
50
|
-
_target = decodeURI(_target);
|
|
51
|
-
}
|
|
52
|
-
// 2. run regex
|
|
53
|
-
if (_target.match(/[0-9]+:[0-9]+/) !== null) {
|
|
54
|
-
return FigmaFileOrNodeIdType.maybe_nodeid;
|
|
55
|
-
}
|
|
46
|
+
if ((0, parse_url_1.formatNodeId)(maybeidlike)) {
|
|
47
|
+
return FigmaFileOrNodeIdType.maybe_nodeid;
|
|
56
48
|
}
|
|
57
49
|
// e.g. kLzb7R9xYuuphfX4TssVNe
|
|
58
50
|
// e.g. 4hqwYFw6FKw1njvzEl3VUh
|
package/dist/parse-url.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ import { FigmaTargetNodeConfig } from "./target-node-config";
|
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
11
|
export declare function parseFileId(url: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Figma file url's node-id changed over time, this function is to make sure we can handle both formats.
|
|
14
|
+
* to keep `00:00` format
|
|
15
|
+
* @param node_id
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatNodeId(node_id: string): string;
|
|
12
19
|
/**
|
|
13
20
|
* pattern is "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
|
|
14
21
|
* @param url
|
package/dist/parse-url.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFileAndNodeId = exports.parseFileId = void 0;
|
|
3
|
+
exports.parseFileAndNodeId = exports.formatNodeId = exports.parseFileId = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* extracts file id from share link
|
|
6
6
|
*
|
|
@@ -20,6 +20,32 @@ function parseFileId(url) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
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;
|
|
23
49
|
/**
|
|
24
50
|
* pattern is "https://www.figma.com/file/Y0Gh77AqBoHH7dG1GtK3xF/?node-id=775%3A112"
|
|
25
51
|
* @param url
|
|
@@ -28,7 +54,7 @@ function parseFileAndNodeId(url) {
|
|
|
28
54
|
try {
|
|
29
55
|
const _url = new URL(url);
|
|
30
56
|
const params = new URLSearchParams(_url.search);
|
|
31
|
-
const nodeId = params.get("node-id");
|
|
57
|
+
const nodeId = formatNodeId(params.get("node-id"));
|
|
32
58
|
const fileId = parseFileId(url);
|
|
33
59
|
return {
|
|
34
60
|
url: url,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@design-sdk/figma-url",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.46",
|
|
4
4
|
"description": "Figma url utils for sharing & embeding and url inspection",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -24,6 +24,5 @@
|
|
|
24
24
|
],
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
27
|
-
}
|
|
28
|
-
"gitHead": "b61dcb1edb6ea0eecfe6597468b9c8ad9f8e6ab0"
|
|
27
|
+
}
|
|
29
28
|
}
|