Glob matching for javascript/node.js, a replacement and faster alternative to minimatch and multimatch
90
Comprehensive brace pattern processing for expanding and manipulating brace expressions like {a,b,c} and {1..10}, powered by the braces library.
Processes brace patterns with options to control expansion behavior.
/**
* Process the given brace pattern
* @param {string} pattern - String with brace pattern to process
* @param {object} options - Any options to change how expansion is performed
* @returns {string[]} Array of processed patterns
*/
function braces(pattern, options);Usage Examples:
const { braces } = require('micromatch');
// Basic alternation - returns regex pattern by default
console.log(braces('foo/{a,b,c}/bar'));
//=> ['foo/(a|b|c)/bar']
// Numeric range
console.log(braces('file{1..3}.txt'));
//=> ['file(1|2|3).txt']
// Character range
console.log(braces('test{a..c}.js'));
//=> ['test(a|b|c).js']Expands brace patterns into individual strings (sets expand: true option automatically).
/**
* Expand braces with expand option enabled
* @param {string} pattern - String with brace pattern to expand
* @param {object} options - Any options to change how expansion is performed
* @returns {string[]} Array of expanded patterns
*/
function braceExpand(pattern, options);Usage Examples:
const { braceExpand } = require('micromatch');
// Expanded alternation
console.log(braceExpand('foo/{a,b,c}/bar'));
//=> ['foo/a/bar', 'foo/b/bar', 'foo/c/bar']
// Expanded numeric range
console.log(braceExpand('file{1..3}.txt'));
//=> ['file1.txt', 'file2.txt', 'file3.txt']
// Expanded character range
console.log(braceExpand('test{a..c}.js'));
//=> ['testa.js', 'testb.js', 'testc.js']
// Complex nested patterns
console.log(braceExpand('src/{app,lib}/{*.js,*.ts}'));
//=> ['src/app/*.js', 'src/app/*.ts', 'src/lib/*.js', 'src/lib/*.ts']Helper function to detect if a string contains brace patterns (exposed for testing purposes).
/**
* Helper function to detect brace patterns in strings
* @param {string} str - String to test for braces
* @returns {boolean} Returns true if string contains brace patterns
*/
function hasBraces(str);Usage Examples:
const { hasBraces } = require('micromatch');
console.log(hasBraces('foo/{a,b,c}/bar')); //=> true
console.log(hasBraces('foo/bar')); //=> false
console.log(hasBraces('file{1..10}.txt')); //=> trueComma-separated alternatives within braces:
// Basic alternation
'{a,b,c}' → ['a', 'b', 'c']
// With surrounding text
'file.{js,ts,json}' → ['file.js', 'file.ts', 'file.json']
// Nested alternation
'{src,test}/{*.js,*.ts}' → ['src/*.js', 'src/*.ts', 'test/*.js', 'test/*.ts']Sequential numeric expansion:
// Basic numeric range
'{1..5}' → ['1', '2', '3', '4', '5']
// With zero padding
'{01..05}' → ['01', '02', '03', '04', '05']
// With step increment
'{1..10..2}' → ['1', '3', '5', '7', '9']
// Negative numbers
'{-2..2}' → ['-2', '-1', '0', '1', '2']Sequential character expansion:
// Basic character range
'{a..e}' → ['a', 'b', 'c', 'd', 'e']
// Uppercase range
'{A..E}' → ['A', 'B', 'C', 'D', 'E']
// Mixed case (preserves case of endpoints)
'{a..E}' → ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E']Multiple brace patterns can be combined:
// Multiple brace sets
'{a,b}{1,2}' → ['a1', 'a2', 'b1', 'b2']
// Mixed pattern types
'{src,test}/file{1..3}.{js,ts}' → [
'src/file1.js', 'src/file1.ts', 'src/file2.js', 'src/file2.ts',
'src/file3.js', 'src/file3.ts', 'test/file1.js', 'test/file1.ts',
'test/file2.js', 'test/file2.ts', 'test/file3.js', 'test/file3.ts'
]expand: true - Return array of expanded strings instead of regex patternnobrace: true - Disable brace expansion (treat braces as literals)expandRange: function - Custom function for expanding rangesrangeLimit: number - Limit the number of range expansions (default: 65536)nodupes: false - Allow duplicate values in resultsunescape: true - Remove escaping from brace characters{} are treated as literal bracesrangeLimit option (default: 65536)braces() and braceExpand() functions delegate to the braces npm packageInstall with Tessl CLI
npx tessl i tessl/npm-micromatchdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10