aico-pack
Version:
A tool to pack repository contents to single file for AI consumption
40 lines • 1.2 kB
JavaScript
/**
* Splits comma-separated glob patterns while preserving brace expansion patterns.
* This ensures patterns with braces are treated as a single pattern,
* rather than being split at commas inside the braces.
* Whitespace around patterns is also trimmed.
*/
export const splitPatterns = (patterns) => {
if (!patterns)
return [];
const result = [];
let currentPattern = '';
let braceLevel = 0;
for (let i = 0; i < patterns.length; i++) {
const char = patterns[i];
if (char === '{') {
braceLevel++;
currentPattern += char;
}
else if (char === '}') {
braceLevel--;
currentPattern += char;
}
else if (char === ',' && braceLevel === 0) {
// Only split on commas when not inside braces
if (currentPattern) {
result.push(currentPattern.trim());
currentPattern = '';
}
}
else {
currentPattern += char;
}
}
// Add the last pattern
if (currentPattern) {
result.push(currentPattern.trim());
}
return result;
};
//# sourceMappingURL=patternUtils.js.map