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

Function generateUniqueClassName

packages/backend/src/html/htmlMain.ts:57–72  ·  view source on GitHub ↗
(prefix = "figma")

Source from the content-addressed store, hash-verified

55
56// Generate a class name - prefer direct uniqueId, but fall back to counter-based if needed
57export function generateUniqueClassName(prefix = "figma"): string {
58 // Sanitize the prefix to ensure valid CSS class
59 const sanitizedPrefix =
60 prefix.replace(/[^a-zA-Z0-9_-]/g, "").replace(/^[0-9_-]/, "f") || // Ensure it doesn't start with a number or special char
61 "figma";
62
63 // Most of the time, we'll just use the prefix directly as it's pre-generated to be unique
64 // But keep the counter logic as a fallback
65 const count = classNameCounters.get(sanitizedPrefix) || 0;
66 classNameCounters.set(sanitizedPrefix, count + 1);
67
68 // Only add suffix if this isn't the first instance
69 return count === 0
70 ? sanitizedPrefix
71 : `${sanitizedPrefix}_${count.toString().padStart(2, "0")}`;
72}
73
74// Reset all class name counters - call this at the start of processing
75export function resetClassNameCounters(): void {

Callers 2

getTextSegmentsMethod · 0.90
constructorMethod · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected