parseTemplateLiteralToCnArgs() — ui Function Reference
Architecture documentation for the parseTemplateLiteralToCnArgs() function in update-fonts.ts from the ui codebase.
Entity Profile
Dependency Diagram
graph TD 15f2fe89_6dc3_a459_ce8f_eacfbfed6026["parseTemplateLiteralToCnArgs()"] b169f1bf_76c5_e7c9_f493_15fe0f296591["update-fonts.ts"] 15f2fe89_6dc3_a459_ce8f_eacfbfed6026 -->|defined in| b169f1bf_76c5_e7c9_f493_15fe0f296591 97bdf019_6ec8_1cbd_1fbb_ed4acd2cc973["updateHtmlClassName()"] 97bdf019_6ec8_1cbd_1fbb_ed4acd2cc973 -->|calls| 15f2fe89_6dc3_a459_ce8f_eacfbfed6026 style 15f2fe89_6dc3_a459_ce8f_eacfbfed6026 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/shadcn/src/utils/updaters/update-fonts.ts lines 480–513
function parseTemplateLiteralToCnArgs(templateLiteral: string) {
// Parse template literal like `${geistSans.variable} ${geistMono.variable} antialiased`
// into cn() arguments with static strings first, then variables:
// ["antialiased", geistSans.variable, geistMono.variable]
const staticArgs: string[] = []
const variableArgs: string[] = []
// Remove the backticks.
const content = templateLiteral.slice(1, -1)
// Split by ${...} expressions and static parts.
const parts = content.split(/(\$\{[^}]+\})/)
for (const part of parts) {
if (!part) continue
if (part.startsWith("${") && part.endsWith("}")) {
// Expression like ${geistSans.variable}.
const expr = part.slice(2, -1).trim()
if (expr) {
variableArgs.push(expr)
}
} else {
// Static string - split by whitespace and add non-empty parts as quoted strings.
const staticParts = part.trim().split(/\s+/).filter(Boolean)
for (const staticPart of staticParts) {
staticArgs.push(`"${staticPart}"`)
}
}
}
// Return static strings first, then variables.
return [...staticArgs, ...variableArgs]
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does parseTemplateLiteralToCnArgs() do?
parseTemplateLiteralToCnArgs() is a function in the ui codebase, defined in packages/shadcn/src/utils/updaters/update-fonts.ts.
Where is parseTemplateLiteralToCnArgs() defined?
parseTemplateLiteralToCnArgs() is defined in packages/shadcn/src/utils/updaters/update-fonts.ts at line 480.
What calls parseTemplateLiteralToCnArgs()?
parseTemplateLiteralToCnArgs() is called by 1 function(s): updateHtmlClassName.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free