(node: any)
| 178 | |
| 179 | // Get a valid React component name from a layer name |
| 180 | export function getReactComponentName(node: any): string { |
| 181 | // Use uniqueName if available, otherwise use name |
| 182 | const name: string = node?.uniqueName || node?.name; |
| 183 | |
| 184 | // Default name if nothing valid is provided |
| 185 | if (!name || name.trim() === "") { |
| 186 | return "App"; |
| 187 | } |
| 188 | |
| 189 | // Convert to PascalCase |
| 190 | let componentName = name |
| 191 | .replace(/[^a-zA-Z0-9_]/g, " ") // Replace non-alphanumeric chars with spaces |
| 192 | .split(/\s+/) // Split by spaces |
| 193 | .map((part) => |
| 194 | part ? part.charAt(0).toUpperCase() + part.slice(1).toLowerCase() : "", |
| 195 | ) |
| 196 | .join(""); |
| 197 | |
| 198 | // Ensure it starts with uppercase letter (React component convention) |
| 199 | componentName = |
| 200 | componentName.charAt(0).toUpperCase() + componentName.slice(1); |
| 201 | |
| 202 | // Ensure it's a valid identifier - if it starts with a number, prefix with 'Component' |
| 203 | if (/^[0-9]/.test(componentName)) { |
| 204 | componentName = "Component" + componentName; |
| 205 | } |
| 206 | |
| 207 | // If we ended up with nothing valid, use the default |
| 208 | return componentName || "App"; |
| 209 | } |
| 210 | |
| 211 | // Get a Svelte-friendly component name |
| 212 | export function getSvelteElementName( |
no outgoing calls
no test coverage detected