MCPcopy Index your code
hub / github.com/codeaashu/claude-code / expandBraces

Function expandBraces

src/utils/frontmatterParser.ts:240–266  ·  view source on GitHub ↗

* Expands brace patterns in a glob string. * @example * expandBraces("src/*.{ts,tsx}") // returns ["src/*.ts", "src/*.tsx"] * expandBraces("{a,b}/{c,d}") // returns ["a/c", "a/d", "b/c", "b/d"]

(pattern: string)

Source from the content-addressed store, hash-verified

238 * expandBraces("{a,b}/{c,d}") // returns ["a/c", "a/d", "b/c", "b/d"]
239 */
240function expandBraces(pattern: string): string[] {
241 // Find the first brace group
242 const braceMatch = pattern.match(/^([^{]*)\{([^}]+)\}(.*)$/)
243
244 if (!braceMatch) {
245 // No braces found, return pattern as-is
246 return [pattern]
247 }
248
249 const prefix = braceMatch[1] || ''
250 const alternatives = braceMatch[2] || ''
251 const suffix = braceMatch[3] || ''
252
253 // Split alternatives by comma and expand each one
254 const parts = alternatives.split(',').map(alt => alt.trim())
255
256 // Recursively expand remaining braces in suffix
257 const expanded: string[] = []
258 for (const part of parts) {
259 const combined = prefix + part + suffix
260 // Recursively handle additional brace groups
261 const furtherExpanded = expandBraces(combined)
262 expanded.push(...furtherExpanded)
263 }
264
265 return expanded
266}
267
268/**
269 * Parses a positive integer value from frontmatter.

Callers 1

splitPathInFrontmatterFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected