MCPcopy
hub / github.com/micromatch/micromatch

github.com/micromatch/micromatch @4.0.8 sqlite

repository ↗ · DeepWiki ↗ · release 4.0.8 ↗
26 symbols 55 edges 48 files 0 documented · 0%
README

micromatch NPM version NPM monthly downloads NPM total downloads Tests

Glob matching for javascript/node.js. A replacement and faster alternative to minimatch and multimatch.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Table of Contents

Details

Install

Install with npm:

$ npm install --save micromatch

Sponsors

Become a Sponsor to add your logo to this README, or any of my other projects

Quickstart

const micromatch = require('micromatch');
// micromatch(list, patterns[, options]);

The main export takes a list of strings and one or more glob patterns:

console.log(micromatch(['foo', 'bar', 'baz', 'qux'], ['f*', 'b*'])) //=> ['foo', 'bar', 'baz']
console.log(micromatch(['foo', 'bar', 'baz', 'qux'], ['*', '!b*'])) //=> ['foo', 'qux']

Use .isMatch() to for boolean matching:

console.log(micromatch.isMatch('foo', 'f*')) //=> true
console.log(micromatch.isMatch('foo', ['b*', 'f*'])) //=> true

Switching from minimatch and multimatch is easy!

Why use micromatch?

micromatch is a replacement for minimatch and multimatch

  • Supports all of the same matching features as minimatch and multimatch
  • More complete support for the Bash 4.3 specification than minimatch and multimatch. Micromatch passes all of the spec tests from bash, including some that bash still fails.
  • Fast & Performant - Loads in about 5ms and performs fast matches.
  • Glob matching - Using wildcards (* and ?), globstars (**) for nested directories
  • Advanced globbing - Supports extglobs, braces, and POSIX brackets, and support for escaping special characters with \ or quotes.
  • Accurate - Covers more scenarios than minimatch
  • Well tested - More than 5,000 test assertions
  • Windows support - More reliable windows support than minimatch and multimatch.
  • Safe - Micromatch is not subject to DoS with brace patterns like minimatch and multimatch.

Matching features

  • Support for multiple glob patterns (no need for wrappers like multimatch)
  • Wildcards (**, *.js)
  • Negation ('!a/*.js', '*!(b).js')
  • extglobs (+(x|y), !(a|b))
  • POSIX character classes ([[:alpha:][:digit:]])
  • brace expansion (foo/{1..5}.md, bar/{a,b,c}.js)
  • regex character classes (foo-[1-5].js)
  • regex logical "or" (foo/(abc|xyz).js)

You can mix and match these features to create whatever patterns you need!

Switching to micromatch

(There is one notable difference between micromatch and minimatch in regards to how backslashes are handled. See the notes about backslashes for more information.)

From minimatch

Use micromatch.isMatch() instead of minimatch():

console.log(micromatch.isMatch('foo', 'b*')); //=> false

Use micromatch.match() instead of minimatch.match():

console.log(micromatch.match(['foo', 'bar'], 'b*')); //=> 'bar'

From multimatch

Same signature:

console.log(micromatch(['foo', 'bar', 'baz'], ['f*', '*z'])); //=> ['foo', 'baz']

API

Params

  • list {String|Array}: List of strings to match.
  • patterns {String|Array}: One or more glob patterns to use for matching.
  • options {Object}: See available options
  • returns {Array}: Returns an array of matches

Example

const mm = require('micromatch');
// mm(list, patterns[, options]);

console.log(mm(['a.js', 'a.txt'], ['*.js']));
//=> [ 'a.js' ]

.matcher

Returns a matcher function from the given glob pattern and options. The returned function takes a string to match as its only argument and returns true if the string is a match.

Params

  • pattern {String}: Glob pattern
  • options {Object}
  • returns {Function}: Returns a matcher function.

Example

const mm = require('micromatch');
// mm.matcher(pattern[, options]);

const isMatch = mm.matcher('*.!(*a)');
console.log(isMatch('a.a')); //=> false
console.log(isMatch('a.b')); //=> true

.isMatch

Returns true if any of the given glob patterns match the specified string.

Params

  • str {String}: The string to test.
  • patterns {String|Array}: One or more glob patterns to use for matching.
  • [options] {Object}: See available options.
  • returns {Boolean}: Returns true if any patterns match str

Example

const mm = require('micromatch');
// mm.isMatch(string, patterns[, options]);

console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
console.log(mm.isMatch('a.a', 'b.*')); //=> false

.not

Returns a list of strings that do not match any of the given patterns.

Params

  • list {Array}: Array of strings to match.
  • patterns {String|Array}: One or more glob pattern to use for matching.
  • options {Object}: See available options for changing how matches are performed
  • returns {Array}: Returns an array of strings that do not match the given patterns.

Example

const mm = require('micromatch');
// mm.not(list, patterns[, options]);

console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
//=> ['b.b', 'c.c']

.contains

Returns true if the given string contains the given pattern. Similar to .isMatch but the pattern can match any part of the string.

Params

  • str {String}: The string to match.
  • patterns {String|Array}: Glob pattern to use for matching.
  • options {Object}: See available options for changing how matches are performed
  • returns {Boolean}: Returns true if any of the patterns matches any part of str.

Example

var mm = require('micromatch');
// mm.contains(string, pattern[, options]);

console.log(mm.contains('aa/bb/cc', '*b'));
//=> true
console.log(mm.contains('aa/bb/cc', '*d'));
//=> false

.matchKeys

Filter the keys of the given object with the given glob pattern and options. Does not attempt to match nested keys. If you need this feature, use glob-object instead.

Params

  • object {Object}: The object with keys to filter.
  • patterns {String|Array}: One or more glob patterns to use for matching.
  • options {Object}: See available options for changing how matches are performed
  • returns {Object}: Returns an object with only keys that match the given patterns.

Example

const mm = require('micromatch');
// mm.matchKeys(object, patterns[, options]);

const obj = { aa: 'a', ab: 'b', ac: 'c' };
console.log(mm.matchKeys(obj, '*b'));
//=> { ab: 'b' }

.some

Returns true if some of the strings in the given list match any of the given glob patterns.

Params

  • list {String|Array}: The string or array of strings to test. Returns as soon as the first match is found.
  • patterns {String|Array}: One or more glob patterns to use for matching.
  • options {Object}: See available options for changing how matches are performed
  • returns {Boolean}: Returns true if any patterns matches any of the strings in list

Example

const mm = require('micromatch');
// mm.some(list, patterns[, options]);

console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
// true
console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
// false

.every

Returns true if every string in the given list matches any of the given glob patterns.

Params

  • list {String|Array}: The string or array of strings to test.
  • patterns {String|Array}: One or more glob patterns to use for matching.
  • options {Object}: See available options for changing how matches are performed
  • returns {Boolean}: Returns true if all patterns matches all of the strings in list

Example

const mm = require('micromatch');
// mm.every(list, patterns[, options]);

console.log(mm.every('foo.js', ['foo.js']));
// true
console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
// true
console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
// false
console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
// false

.all

Returns true if all of the given patterns match the specified string.

Params

  • str {String|Array}: The string to test.
  • patterns {String|Array}: One or more glob patterns to use for matching.
  • options {Object}: See available options for changing how matches are performed
  • returns {Boolean}: Returns true if any patterns match str

Example

const mm = require('micromatch');
// mm.all(string, patterns[, options]);

console.log(mm.all('foo.js', ['foo.js']));
// true

console.log(mm.all('foo.js', ['*.js', '!foo.js']));
// false

console.log(mm.all('foo.js', ['*.js', 'foo.js']));
// true

console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
// true

.capture

Returns an array of matches captured by pattern in string, ornull` if the pattern did not match.

Params

  • glob {String}: Glob pattern to use for matching.
  • input {String}: String to match
  • options {Object}: See available options for changing how matches are performed
  • returns {Array|null}: Returns an array of captures if the input matches the glob pattern, otherwise null.

Example

const mm = require('micromatch');
// mm.capture(pattern, string[, options]);

console.log(mm.capture('test/*.js', 'test/foo.js'));
//=> ['foo']
console.log(mm.capture('test/*.js', 'foo/bar.css'));
//=> null

.makeRe

Create a regular expression from the given glob pattern.

Params

  • pattern {String}: A glob pattern to convert to regex.
  • options {Object}
  • returns {RegExp}: Returns a regex created from the given pattern.

Example

const mm = require('micromatch');
// mm.makeRe(pattern[, options]);

console.log(mm.makeRe('*.js'));
//=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/

.scan

Scan a glob pattern to separate the pattern into segments. Used by the split method.

Params

  • pattern {String}
  • options {Object}
  • returns {Object}: Returns an object with

Example

const mm = require('micromatch');
const state = mm.scan(pattern[, options]);

.parse

Parse a glob pattern to create the source string for a regular expression.

Params

  • glob {String}
  • options {Object}
  • returns {Object}: Returns an object with useful properties and output to be used as regex source string.

Example

const mm = require('micromatch');
const state = mm.parse(pattern[, options]);

.braces

Process the given brace pattern.

Params

  • pattern {String}: String with brace pattern to process.
  • options **{Obje

Core symbols most depended-on inside this repo

isMatch
called by 4343
test/posix-classes.js
optimize
called by 176
test/braces-compiled.js
hasBraces
called by 13
index.js
convert
called by 13
test/posix-classes.js
bench
called by 12
bench/index.js
generate
called by 4
test/malicious.js
isEmptyString
called by 2
index.js
micromatch
called by 2
index.js

Shape

Function 26

Languages

TypeScript100%

Modules by API surface

index.js4 symbols
test/minimatch.js3 symbols
test/posix-classes.js2 symbols
test/bash.js2 symbols
bench/index.js2 symbols
test/special-characters.js1 symbols
test/options.js1 symbols
test/negation.js1 symbols
test/malicious.js1 symbols
test/dotfiles.js1 symbols
test/braces-compiled.js1 symbols
test/api.not.js1 symbols

Dependencies from manifests, versioned

ansi-colors4.1.1 · 1×
benchmark2.1.4 · 1×
braces3.0.3 · 1×
fill-range7.0.1 · 1×
glob-parent6.0.2 · 1×
gulp-format-md2.0.0 · 1×
minimatch5.0.1 · 1×
minimist1.2.6 · 1×
mocha9.2.2 · 1×
picomatch2.3.1 · 1×
time-requiregithub:jonschlinkert · 1×

For agents

$ claude mcp add micromatch \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact