(input: string | string[])
| 187 | * splitPathInFrontmatter(["a", "src/*.{ts,tsx}"]) // returns ["a", "src/*.ts", "src/*.tsx"] |
| 188 | */ |
| 189 | export function splitPathInFrontmatter(input: string | string[]): string[] { |
| 190 | if (Array.isArray(input)) { |
| 191 | return input.flatMap(splitPathInFrontmatter) |
| 192 | } |
| 193 | if (typeof input !== 'string') { |
| 194 | return [] |
| 195 | } |
| 196 | // Split by comma while respecting braces |
| 197 | const parts: string[] = [] |
| 198 | let current = '' |
| 199 | let braceDepth = 0 |
| 200 | |
| 201 | for (let i = 0; i < input.length; i++) { |
| 202 | const char = input[i] |
| 203 | |
| 204 | if (char === '{') { |
| 205 | braceDepth++ |
| 206 | current += char |
| 207 | } else if (char === '}') { |
| 208 | braceDepth-- |
| 209 | current += char |
| 210 | } else if (char === ',' && braceDepth === 0) { |
| 211 | // Split here - we're at a comma outside of braces |
| 212 | const trimmed = current.trim() |
| 213 | if (trimmed) { |
| 214 | parts.push(trimmed) |
| 215 | } |
| 216 | current = '' |
| 217 | } else { |
| 218 | current += char |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // Add the last part |
| 223 | const trimmed = current.trim() |
| 224 | if (trimmed) { |
| 225 | parts.push(trimmed) |
| 226 | } |
| 227 | |
| 228 | // Expand brace patterns in each part |
| 229 | return parts |
| 230 | .filter(p => p.length > 0) |
| 231 | .flatMap(pattern => expandBraces(pattern)) |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Expands brace patterns in a glob string. |
no test coverage detected