MCPcopy Index your code
hub / github.com/MigoXLab/coderio / parseFigmaUrl

Function parseFigmaUrl

src/utils/url-parser.ts:11–35  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

9 * // Returns: { fileId: 'aONcu8L82l1PdcT304Q8Za', name: 'intern', nodeId: '0-495' }
10 */
11export const parseFigmaUrl = (url: string): FigmaUrlInfo => {
12 let fileId: string | null = null;
13 let name = 'untitled';
14 let nodeId: string | null = null;
15
16 try {
17 const urlObj = new URL(decodeURIComponent(url));
18 const pathParts = urlObj.pathname.split('/').filter(Boolean);
19 if (pathParts.length >= 3) {
20 fileId = pathParts[pathParts.length - 2] || null;
21 const fileName = pathParts[pathParts.length - 1];
22 name = fileName ? encodeURI(fileName).toLowerCase() : 'untitled';
23 name = name.length > 20 ? name.substring(0, 20) : name;
24 }
25
26 nodeId = urlObj.searchParams.get('node-id') || null;
27 nodeId = nodeId ? nodeId.replace(/-/g, ':') : null;
28 } catch {}
29
30 if (!fileId || !nodeId) {
31 throw new Error('Invalid Figma URL');
32 }
33
34 return { fileId, name, nodeId, projectName: `${name}_${nodeId.replace(/:/g, '_')}` };
35};

Callers 6

design2codeFunction · 0.90
registerD2PCommandFunction · 0.90
registerImagesCommandFunction · 0.90
url-parser.test.tsFile · 0.90
mainFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected