Glob matching for javascript/node.js, a replacement and faster alternative to minimatch and multimatch
90
Core functionality for filtering arrays of strings against glob patterns with support for negation, advanced patterns, and extensive configuration options.
The primary micromatch function that filters strings from a list using one or more glob patterns.
/**
* Returns an array of strings that match one or more glob patterns
* @param {string|string[]} list - List of strings to match
* @param {string|string[]} patterns - One or more glob patterns to use for matching
* @param {object} options - See available options for changing how matches are performed
* @returns {string[]} Returns an array of matches
*/
function micromatch(list, patterns, options);Usage Examples:
const micromatch = require('micromatch');
// Basic matching
console.log(micromatch(['foo', 'bar', 'baz', 'qux'], ['f*', 'b*']));
//=> ['foo', 'bar', 'baz']
// Negation patterns
console.log(micromatch(['foo', 'bar', 'baz', 'qux'], ['*', '!b*']));
//=> ['foo', 'qux']
// Multiple patterns with options
const files = ['src/app.js', 'test/app.test.js', 'docs/readme.md'];
console.log(micromatch(files, '**/*.js', { dot: true }));
//=> ['src/app.js', 'test/app.test.js']Backwards compatibility alias for the main micromatch function.
/**
* Alias for micromatch() - backwards compatibility
* @param {string|string[]} list - List of strings to match
* @param {string|string[]} patterns - One or more glob patterns
* @param {object} options - See available options
* @returns {string[]} Returns an array of matches
*/
micromatch.match = micromatch;Supports standard glob patterns:
* - Matches any number of characters (except path separators)? - Matches a single character[abc] - Matches any character in the set[a-z] - Matches any character in the range** - Matches directories recursively (globstar)When extglobs are enabled (default):
!(pattern) - Negation?(pattern) - Zero or one occurrence+(pattern) - One or more occurrences*(pattern) - Zero or more occurrences@(pattern) - Exactly one occurrenceSupports brace patterns like:
{a,b,c} - Alternation{1..10} - Numeric ranges{a..z} - Character rangesLeading ! in patterns negates the match:
// Exclude .test.js files
micromatch(files, ['**/*.js', '!**/*.test.js']);Error when failglob: true option is set and no matches are found[] when no matches found (default behavior)nonull and nullglob options for controlling empty result behaviornoextglob, nobrace)Install 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