1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export function parseFigmaURL(url) {
const regex = /^https:\/\/www.figma.com\/file\/([^/]+)\/([^/?]+)(\?[^/#]+)?/;
const match = url.match(regex);
if (match) {
const [, key, title, queryParams] = match;
const queryParamsRegex = /[?&]([^=#]+)=([^&#]*)/g;
let params = {};
// Parse query parameters
let paramMatch;
while ((paramMatch = queryParamsRegex.exec(queryParams))) {
const [, name, value] = paramMatch;
params[name] = decodeURIComponent(value);
}
return {
file: params["node-id"] ? Number(params["node-id"]) : null,
key: key,
title: decodeURIComponent(title),
...params,
};
}
return null; // Return null if the URL doesn't match the expected format
}