Skip to main content

micromatch

Interfaces

Item

Properties

PropertyType

glob

string

input

string

output

string

regex

RegExp


Options

Extended by

Properties

PropertyTypeDescription

basename?

boolean

Allow glob patterns without slashes to match a file path based on its basename. Same behavior as minimatch option matchBase.

Default

false;

Example

mm(["a/b.js", "a/c.md"], "*.js");
//=> []

mm(["a/b.js", "a/c.md"], "*.js", { matchBase: true });
//=> ['a/b.js']

bash?

boolean

Enabled by default, this option enforces bash-like behavior with stars immediately following a bracket expression. Bash bracket expressions are similar to regex character classes, but unlike regex, a star following a bracket expression does not repeat the bracketed characters. Instead, the star is treated the same as an other star.

Default

true;

Example

var files = ["abc", "ajz"];
console.log(mm(files, "[a-c]*"));
//=> ['abc', 'ajz']

console.log(mm(files, "[a-c]*", { bash: false }));

capture?

boolean

Return regex matches in supporting methods.

Default

undefined;

contains?

boolean

Allows glob to match any part of the given string(s).

Default

undefined;

cwd?

string

Current working directory. Used by picomatch.split()

Default

process.cwd();

debug?

boolean

Debug regular expressions when an error is thrown.

Default

undefined;

dot?

boolean

Match dotfiles. Otherwise dotfiles are ignored unless a . is explicitly defined in the pattern.

Default

false;

expandRange?

(left: string, right: string, options: Options) => string

Custom function for expanding ranges in brace patterns, such as {a..z}. The function receives the range values as two arguments, and it must return a string to be used in the generated regex. It's recommended that returned strings be wrapped in parentheses. This option is overridden by the expandBrace option.

Default

undefined;

failglob?

boolean

Similar to the --failglob behavior in Bash, throws an error when no matches are found.

Default

false;

fastpaths?

boolean

To speed up processing, full parsing is skipped for a handful common glob patterns. Disable this behavior by setting this option to false.

Default

true;

flags?

boolean

Regex flags to use in the generated regex. If defined, the nocase option will be overridden.

Default

undefined;

format?

(returnedString: string) => string

Custom function for formatting the returned string. This is useful for removing leading slashes, converting Windows paths to Posix paths, etc.

Default

undefined;

ignore?

string | readonly string[]

One or more glob patterns for excluding strings that should not be matched from the result.

Default

undefined;

keepQuotes?

boolean

Retain quotes in the generated regex, since quotes may also be used as an alternative to backslashes.

Default

false;

literalBrackets?

boolean

When true, brackets in the glob pattern will be escaped so that only literal brackets will be matched.

Default

undefined;

lookbehinds?

boolean

Support regex positive and negative lookbehinds. Note that you must be using Node 8.1.10 or higher to enable regex lookbehinds.

Default

true;

matchBase?

boolean

Alias for basename.

Default

false;

maxLength?

number

Limit the max length of the input string. An error is thrown if the input string is longer than this value.

Default

65536;

nobrace?

boolean

Disable brace matching, so that {a,b} and {1..3} would be treated as literal characters.

Default

false;

nobracket?

boolean

Disable matching with regex brackets.

Default

undefined;

nocase?

boolean

Perform case-insensitive matching. Equivalent to the regex i flag. Note that this option is ignored when the flags option is defined.

Default

false;

noext?

boolean

Alias for noextglob

Default

false;

noextglob?

boolean

Disable support for matching with extglobs (like +(a|b))

Default

false;

noglobstar?

boolean

Disable matching with globstars (**).

Default

undefined;

nonegate?

boolean

Disallow negation (!) patterns, and treat leading ! as a literal character to match.

Default

undefined;

noquantifiers?

boolean

Disable support for regex quantifiers (like a{1,2}) and treat them as brace patterns to be expanded.

Default

false;

onIgnore?

(item: Item) => void

Function to be called on ignored items.

Default

undefined;

onMatch?

(item: Item) => void

Function to be called on matched items.

Default

undefined;

onResult?

(item: Item) => void

Function to be called on all items, regardless of whether or not they are matched or ignored.

Default

undefined;

posix?

boolean

Support POSIX character classes ("posix brackets").

Default

false;

prepend?

boolean

String to prepend to the generated regex used for matching.

Default

undefined;

regex?

boolean

Use regular expression rules for + (instead of matching literal +), and for stars that follow closing parentheses or brackets (as in )* and ]*).

Default

false;

strictBrackets?

boolean

Throw an error if brackets, braces, or parens are imbalanced.

Default

undefined;

strictSlashes?

boolean

When true, picomatch won't match trailing slashes with single stars.

Default

undefined;

unescape?

boolean

Remove backslashes from returned matches.

Default

undefined;

Example

In this example we want to match a literal *:

mm.match(["abc", "a\\*c"], "a\\*c");
//=> ['a\\*c']

mm.match(["abc", "a\\*c"], "a\\*c", { unescape: true });
//=> ['a*c']

windows?

boolean

Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself

Default

undefined;

ScanInfo

Extended by

Properties

PropertyType

base

string

glob

string

input

string

isBrace

boolean

isBracket

boolean

isExtglob

boolean

isGlob

boolean

isGlobstar

boolean

negated

boolean

negatedExtglob

boolean

prefix

string

start

number


ScanInfoToken

Properties

PropertyType

depth

number

isGlob

boolean

value

string

backslashes?

boolean

isBrace?

boolean

isBracket?

boolean

isExtglob?

boolean

isGlobstar?

boolean

isPrefix?

boolean

negated?

boolean


ScanInfoWithParts

Extends

Extended by

Properties

PropertyTypeInherited from

base

string

ScanInfo.base

glob

string

ScanInfo.glob

input

string

ScanInfo.input

isBrace

boolean

ScanInfo.isBrace

isBracket

boolean

ScanInfo.isBracket

isExtglob

boolean

ScanInfo.isExtglob

isGlob

boolean

ScanInfo.isGlob

isGlobstar

boolean

ScanInfo.isGlobstar

negated

boolean

ScanInfo.negated

negatedExtglob

boolean

ScanInfo.negatedExtglob

parts

string[]

prefix

string

ScanInfo.prefix

slashes

number[]

start

number

ScanInfo.start


ScanInfoWithTokens

Extends

Properties

PropertyTypeInherited from

base

string

ScanInfoWithParts.base

glob

string

ScanInfoWithParts.glob

input

string

ScanInfoWithParts.input

isBrace

boolean

ScanInfoWithParts.isBrace

isBracket

boolean

ScanInfoWithParts.isBracket

isExtglob

boolean

ScanInfoWithParts.isExtglob

isGlob

boolean

ScanInfoWithParts.isGlob

isGlobstar

boolean

ScanInfoWithParts.isGlobstar

maxDepth

number

negated

boolean

ScanInfoWithParts.negated

negatedExtglob

boolean

ScanInfoWithParts.negatedExtglob

parts

string[]

ScanInfoWithParts.parts

prefix

string

ScanInfoWithParts.prefix

slashes

number[]

ScanInfoWithParts.slashes

start

number

ScanInfoWithParts.start

tokens

ScanInfoToken[]


ScanOptions

Extends

Properties

PropertyTypeDescriptionInherited from

basename?

boolean

Allow glob patterns without slashes to match a file path based on its basename. Same behavior as minimatch option matchBase.

Default

false;

Example

mm(["a/b.js", "a/c.md"], "*.js");
//=> []

mm(["a/b.js", "a/c.md"], "*.js", { matchBase: true });
//=> ['a/b.js']

Options.basename

bash?

boolean

Enabled by default, this option enforces bash-like behavior with stars immediately following a bracket expression. Bash bracket expressions are similar to regex character classes, but unlike regex, a star following a bracket expression does not repeat the bracketed characters. Instead, the star is treated the same as an other star.

Default

true;

Example

var files = ["abc", "ajz"];
console.log(mm(files, "[a-c]*"));
//=> ['abc', 'ajz']

console.log(mm(files, "[a-c]*", { bash: false }));

Options.bash

capture?

boolean

Return regex matches in supporting methods.

Default

undefined;

Options.capture

contains?

boolean

Allows glob to match any part of the given string(s).

Default

undefined;

Options.contains

cwd?

string

Current working directory. Used by picomatch.split()

Default

process.cwd();

Options.cwd

debug?

boolean

Debug regular expressions when an error is thrown.

Default

undefined;

Options.debug

dot?

boolean

Match dotfiles. Otherwise dotfiles are ignored unless a . is explicitly defined in the pattern.

Default

false;

Options.dot

expandRange?

(left: string, right: string, options: Options) => string

Custom function for expanding ranges in brace patterns, such as {a..z}. The function receives the range values as two arguments, and it must return a string to be used in the generated regex. It's recommended that returned strings be wrapped in parentheses. This option is overridden by the expandBrace option.

Default

undefined;

Options.expandRange

failglob?

boolean

Similar to the --failglob behavior in Bash, throws an error when no matches are found.

Default

false;

Options.failglob

fastpaths?

boolean

To speed up processing, full parsing is skipped for a handful common glob patterns. Disable this behavior by setting this option to false.

Default

true;

Options.fastpaths

flags?

boolean

Regex flags to use in the generated regex. If defined, the nocase option will be overridden.

Default

undefined;

Options.flags

format?

(returnedString: string) => string

Custom function for formatting the returned string. This is useful for removing leading slashes, converting Windows paths to Posix paths, etc.

Default

undefined;

Options.format

ignore?

string | readonly string[]

One or more glob patterns for excluding strings that should not be matched from the result.

Default

undefined;

Options.ignore

keepQuotes?

boolean

Retain quotes in the generated regex, since quotes may also be used as an alternative to backslashes.

Default

false;

Options.keepQuotes

literalBrackets?

boolean

When true, brackets in the glob pattern will be escaped so that only literal brackets will be matched.

Default

undefined;

Options.literalBrackets

lookbehinds?

boolean

Support regex positive and negative lookbehinds. Note that you must be using Node 8.1.10 or higher to enable regex lookbehinds.

Default

true;

Options.lookbehinds

matchBase?

boolean

Alias for basename.

Default

false;

Options.matchBase

maxLength?

number

Limit the max length of the input string. An error is thrown if the input string is longer than this value.

Default

65536;

Options.maxLength

nobrace?

boolean

Disable brace matching, so that {a,b} and {1..3} would be treated as literal characters.

Default

false;

Options.nobrace

nobracket?

boolean

Disable matching with regex brackets.

Default

undefined;

Options.nobracket

nocase?

boolean

Perform case-insensitive matching. Equivalent to the regex i flag. Note that this option is ignored when the flags option is defined.

Default

false;

Options.nocase

noext?

boolean

Alias for noextglob

Default

false;

Options.noext

noextglob?

boolean

Disable support for matching with extglobs (like +(a|b))

Default

false;

Options.noextglob

noglobstar?

boolean

Disable matching with globstars (**).

Default

undefined;

Options.noglobstar

nonegate?

boolean

Disallow negation (!) patterns, and treat leading ! as a literal character to match.

Default

undefined;

Options.nonegate

noquantifiers?

boolean

Disable support for regex quantifiers (like a{1,2}) and treat them as brace patterns to be expanded.

Default

false;

Options.noquantifiers

onIgnore?

(item: Item) => void

Function to be called on ignored items.

Default

undefined;

Options.onIgnore

onMatch?

(item: Item) => void

Function to be called on matched items.

Default

undefined;

Options.onMatch

onResult?

(item: Item) => void

Function to be called on all items, regardless of whether or not they are matched or ignored.

Default

undefined;

Options.onResult

parts?

boolean

When true, the returned object will include an array of strings representing each path "segment" in the scanned glob pattern. This is automatically enabled when options.tokens is true.

Default

false;

posix?

boolean

Support POSIX character classes ("posix brackets").

Default

false;

Options.posix

prepend?

boolean

String to prepend to the generated regex used for matching.

Default

undefined;

Options.prepend

regex?

boolean

Use regular expression rules for + (instead of matching literal +), and for stars that follow closing parentheses or brackets (as in )* and ]*).

Default

false;

Options.regex

strictBrackets?

boolean

Throw an error if brackets, braces, or parens are imbalanced.

Default

undefined;

Options.strictBrackets

strictSlashes?

boolean

When true, picomatch won't match trailing slashes with single stars.

Default

undefined;

Options.strictSlashes

tokens?

boolean

When true, the returned object will include an array of tokens (objects), representing each path "segment" in the scanned glob pattern.

Default

false;

unescape?

boolean

Remove backslashes from returned matches.

Default

undefined;

Example

In this example we want to match a literal *:

mm.match(["abc", "a\\*c"], "a\\*c");
//=> ['a\\*c']

mm.match(["abc", "a\\*c"], "a\\*c", { unescape: true });
//=> ['a*c']

Options.unescape

windows?

boolean

Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself

Default

undefined;

Options.windows