dynamate-design-to-code
Version:
A powerful tool for converting Figma designs into high-quality, production-ready code with built-in best practices and customizable rulesets
31 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseFigmaUrl = void 0;
/**
* Parse a Figma URL or section link to extract fileId and nodeId
* Supports both full URLs and section links
*/
function parseFigmaUrl(url) {
try {
// Handle full Figma URLs
if (url.includes('figma.com')) {
const urlObj = new URL(url);
const pathParts = urlObj.pathname.split('/');
const fileId = pathParts[pathParts.indexOf('file') + 1];
const nodeId = urlObj.searchParams.get('node-id') || '';
return { fileId, nodeId };
}
// Handle section links (format: fileId?node-id=nodeId)
const [fileId, params] = url.split('?');
const nodeId = new URLSearchParams(params).get('node-id') || '';
if (!fileId || !nodeId) {
throw new Error('Invalid Figma link format');
}
return { fileId, nodeId };
}
catch (error) {
throw new Error('Failed to parse Figma URL. Please ensure you\'re using a valid Figma link.');
}
}
exports.parseFigmaUrl = parseFigmaUrl;
//# sourceMappingURL=figma.js.map