MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / getComponentName

Function getComponentName

packages/backend/src/html/htmlMain.ts:103–135  ·  view source on GitHub ↗
(
  nodeName: string | undefined,
  className: string,
  nodeType: string,
)

Source from the content-addressed store, hash-verified

101
102// Get proper component name from node info
103export function getComponentName(
104 nodeName: string | undefined,
105 className: string,
106 nodeType: string,
107): string {
108 // Start with Styled prefix
109 let name = "Styled";
110
111 // Try to use node name first
112 if (nodeName && nodeName.length > 0) {
113 // Clean up the node name and capitalize first letter
114 const cleanName = nodeName
115 .replace(/[^a-zA-Z0-9]/g, "")
116 .replace(/^[a-z]/, (match) => match.toUpperCase());
117
118 name += cleanName || nodeType.charAt(0).toUpperCase() + nodeType.slice(1);
119 }
120 // Fall back to className if provided
121 else if (className) {
122 const parts = className.split("-");
123 if (parts.length > 0 && parts[0]) {
124 name += parts[0].charAt(0).toUpperCase() + parts[0].slice(1);
125 } else {
126 name += nodeType.charAt(0).toUpperCase() + nodeType.slice(1);
127 }
128 }
129 // Last resort
130 else {
131 name += nodeType.charAt(0).toUpperCase() + nodeType.slice(1);
132 }
133
134 return name;
135}
136
137// Get the collected CSS as a string with improved formatting
138export function getCollectedCSS(): string {

Callers 2

getTextSegmentsMethod · 0.90
storeStylesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected