(url: string)
| 9 | * // Returns: { fileId: 'aONcu8L82l1PdcT304Q8Za', name: 'intern', nodeId: '0-495' } |
| 10 | */ |
| 11 | export 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 | }; |
no outgoing calls
no test coverage detected