JAEGIS-METHOD-v2.0\v2.1.1\JAEGIS\JAEGIS_Core\JAEGIS-METHOD\node_modules\micromatch\README
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 โค๏ธ and support.
Table of Contents
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
The main export takes a list of strings and one or more glob patterns:
Use .isMatch() to for boolean matching:
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 directoriesAdvanced 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():
Use micromatch.match() instead of minimatch.match():
From multimatch
Same signature:
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 optionsreturns{Array}: Returns an array of matches
Example
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 patternoptions{Object}returns{Function}: Returns a matcher function.
Example
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 matchstr
Example
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 performedreturns{Array}: Returns an array of strings that do not match the given patterns.
Example
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 performedreturns{Boolean}: Returns true if any of the patterns matches any part ofstr.
Example
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 performedreturns{Object}: Returns an object with only keys that match the given patterns.
Example
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 performedreturns{Boolean}: Returns true if anypatternsmatches any of the strings inlist
Example
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 performedreturns{Boolean}: Returns true if allpatternsmatches all of the strings inlist
Example
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 performedreturns{Boolean}: Returns true if any patterns matchstr
Example
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 matchoptions{Object}: See available options for changing how matches are performedreturns{Array|null}: Returns an array of captures if the input matches the glob pattern, otherwisenull.
Example
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
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
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
Process the given brace pattern.
Params
pattern{String}: String with brace pattern to process.returns{Array}
Example
Options
Option
Type
Default value
Description
basename
boolean
false
If set, then patterns without slashes will be matched against the basename of the path if it contains slashes. For example, a?b would match the path /xyz/123/acb, but not /xyz/acb/123.
bash
boolean
false
Follow bash matching rules more strictly - disallows backslashes as escape characters, and treats single stars as globstars (**).
capture
boolean
undefined
Return regex matches in supporting methods.
contains
boolean
undefined
Allows glob to match any part of the given string(s).
cwd
string
process.cwd()
Current working directory. Used by picomatch.split()
debug
boolean
undefined
Debug regular expressions when an error is thrown.
dot
boolean
false
Match dotfiles. Otherwise dotfiles are ignored unless a . is explicitly defined in the pattern.
expandRange
function
undefined
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.
failglob
boolean
false
Similar to the failglob behavior in Bash, throws an error when no matches are found. Based on the bash option of the same name.
fastpaths
boolean
true
To speed up processing, full parsing is skipped for a handful common glob patterns. Disable this behavior by setting this option to false.
flags
boolean
undefined
Regex flags to use in the generated regex. If defined, the nocase option will be overridden.
function
undefined
Custom function for formatting the returned string. This is useful for removing leading slashes, converting Windows paths to Posix paths, etc.
ignore
array|string
undefined
One or more glob patterns for excluding strings that should not be matched from the result.
keepQuotes
boolean
false
Retain quotes in the generated regex, since quotes may also be used as an alternative to backslashes.
literalBrackets
boolean
undefined
When true, brackets in the glob pattern will be escaped so that only literal brackets will be matched.
lookbehinds
boolean
true
Support regex positive and negative lookbehinds. Note that you must be using Node 8.1.10 or higher to enable regex lookbehinds.
matchBase
boolean
false
Alias for basename
maxLength
boolean
65536
Limit the max length of the input string. An error is thrown if the input string is longer than this value.
nobrace
boolean
false
Disable brace matching, so that {a,b} and {1..3} would be treated as literal characters.
nobracket
boolean
undefined
Disable matching with regex brackets.
nocase
boolean
false
Perform case-insensitive matching. Equivalent to the regex i flag. Note that this option is ignored when the flags option is defined.
nodupes
boolean
true
Deprecated, use nounique instead. This option will be removed in a future major release. By default duplicates are removed. Disable uniquification by setting this option to false.
noext
boolean
false
Alias for noextglob
noglobstar
boolean
false
Disable support for matching nested directories with globstars (**)
nonegate
boolean
false
Disable support for negating with leading !
noquantifiers
boolean
false
Disable support for regex quantifiers (like a{1,2}) and treat them as brace patterns to be expanded.
function
undefined
Function to be called on all items, regardless of whether or not they are matched or ignored.
posixSlashes
boolean
undefined
Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself
prepend
string
undefined
String to prepend to the generated regex used for matching.
regex
boolean
false
Use regular expression rules for + (instead of matching literal +), and for stars that follow closing parentheses or brackets (as in )* and ]*).
strictBrackets
boolean
undefined
Throw an error if brackets, braces, or parens are imbalanced.
strictSlashes
boolean
undefined
When true, picomatch won't match trailing slashes with single stars.
unescape
boolean
undefined
Remove preceding backslashes from escaped glob characters before creating the regular expression to perform matches.
unixify
boolean
undefined
Alias for posixSlashes, for backwards compatitibility.
Options Examples
options.basename
Allow glob patterns without slashes to match a file path based on its basename. Same behavior as minimatch option matchBase.
Type: Boolean
Default: false
Example
options.bash
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 any other star.
Type: Boolean
Default: true
Example
options.expandRange
Type: function
Default: undefined
Custom function for expanding ranges in brace patterns. The fill-range library is ideal for this purpose, or you can use custom code to do whatever you need.
Example
The following example shows how to create a glob that matches a numeric folder name between 01 and 25, with leading zeros.
options.format
Type: function
Default: undefined
Custom function for formatting strings before they're matched.
Example
options.ignore
String or array of glob patterns to match files to ignore.
Type: String|Array
Default: undefined
options.matchBase
Alias for options.basename.
options.noextglob
Disable extglob support, so that extglobs are regarded as literal characters.
Type: Boolean
Default: undefined
Examples
options.nonegate
Disallow negation (!) patterns, and treat leading ! as a literal character to match.
Type: Boolean
Default: undefined
options.noglobstar
Disable matching with globstars (**).
Type: Boolean
Default: undefined
options.nonull
Alias for options.nullglob.
options.nullglob
If true, when no matches are found the actual (arrayified) glob pattern is returned instead of an empty array. Same behavior as minimatch option nonull.
Type: Boolean
Default: undefined
options.onIgnore
options.onMatch
options.onResult
options.posixSlashes
Convert path separators on returned files to posix/unix-style forward slashes. Aliased as unixify for backwards compatibility.
Type: Boolean
Default: true on windows, false everywhere else.
Example
options.unescape
Remove backslashes from escaped glob characters before creating the regular expression to perform matches.
Type: Boolean
Default: undefined
Example
In this example we want to match a literal *:
Extended globbing
Micromatch supports the following extended globbing features.
Extglobs
Extended globbing, as described by the bash man page:
pattern
regex equivalent
description
?(pattern)
(pattern)?
Matches zero or one occurrence of the given patterns
*(pattern)
(pattern)*
Matches zero or more occurrences of the given patterns
+(pattern)
(pattern)+
Matches one or more occurrences of the given patterns
@(pattern)
(pattern) *
Matches one of the given patterns
!(pattern)
N/A (equivalent regex is much more complicated)
Matches anything except one of the given patterns
* Note that @ isn't a regex character.
Braces
Brace patterns can be used to match specific ranges or sets of characters.
Example
The pattern {f,b}*/{1..3}/{b,q}* would match any of following strings:
Visit braces to see the full range of features and options related to brace expansion, or to create brace matching or expansion related issues.
Regex character classes
Given the list: ['a.js', 'b.js', 'c.js', 'd.js', 'E.js']:
[ac].js: matches bothaandc, returning['a.js', 'c.js'][b-d].js: matches frombtod, returning['b.js', 'c.js', 'd.js']a/[A-Z].js: matches and uppercase letter, returning['a/E.md']
Learn about regex character classes.
Regex groups
Given ['a.js', 'b.js', 'c.js', 'd.js', 'E.js']:
(a|c).js: would match eitheraorc, returning['a.js', 'c.js'](b|d).js: would match eitherbord, returning['b.js', 'd.js'](b|[A-Z]).js: would match eitherbor an uppercase letter, returning['b.js', 'E.js']
As with regex, parens can be nested, so patterns like ((a|b)|c)/b will work. Although brace expansion might be friendlier to use, depending on preference.
POSIX bracket expressions
POSIX brackets are intended to be more user-friendly than regex character classes. This of course is in the eye of the beholder.
Example
Notes
Bash 4.3 parity
Whenever possible matching behavior is based on behavior Bash 4.3, which is mostly consistent with minimatch.
However, it's suprising how many edge cases and rabbit holes there are with glob matching, and since there is no real glob specification, and micromatch is more accurate than both Bash and minimatch, there are cases where best-guesses were made for behavior. In a few cases where Bash had no answers, we used wildmatch (used by git) as a fallback.
Backslashes
There is an important, notable difference between minimatch and micromatch in regards to how backslashes are handled in glob patterns.
Micromatch exclusively and explicitly reserves backslashes for escaping characters in a glob pattern, even on windows, which is consistent with bash behavior. More importantly, unescaping globs can result in unsafe regular expressions.
Minimatch converts all backslashes to forward slashes, which means you can't use backslashes to escape any characters in your glob patterns.
We made this decision for micromatch for a couple of reasons:
Consistency with bash conventions.
Glob patterns are not filepaths. They are a type of regular language that is converted to a JavaScript regular expression. Thus, when forward slashes are defined in a glob pattern, the resulting regular expression will match windows or POSIX path separators just fine.
A note about joining paths to globs
Note that when you pass something like path.join('foo', '*') to micromatch, you are creating a filepath and expecting it to still work as a glob pattern. This causes problems on windows, since the path.sep is \\.
In other words, since \\ is reserved as an escape character in globs, on windows path.join('foo', '*') would result in foo\\*, which tells micromatch to match * as a literal character. This is the same behavior as bash.
To solve this, you might be inspired to do something like 'foo\\*'.replace(/\\/g, '/'), but this causes another, potentially much more serious, problem.
Benchmarks
Running benchmarks
Install dependencies for running benchmarks:
Run the benchmarks:
Latest results
As of August 23, 2024 (longer bars are better):
Contributing
All contributions are welcome! Please read the contributing guide to get started.
Bug reports
Please create an issue if you encounter a bug or matching behavior that doesn't seem correct. If you find a matching-related issue, please:
research existing issues first (open and closed)
visit the GNU Bash documentation to see how Bash deals with the pattern
visit the minimatch documentation to cross-check expected behavior in node.js
if all else fails, since there is no real specification for globs we will probably need to discuss expected behavior and decide how to resolve it. which means any detail you can provide to help with this discussion would be greatly appreciated.
Platform issues
It's important to us that micromatch work consistently on all platforms. If you encounter any platform-specific matching or path related issues, please let us know (pull requests are also greatly appreciated).
About
Related projects
You might also be interested in these projects:
expand-brackets: Expand POSIX bracket expressions (character classes) in glob patterns. | homepage
fill-range: Fill in a range of numbers or letters, optionally passing an increment or
steptoโฆ more | homepage
Contributors
Commits
Contributor
12
Author
Jon Schlinkert
License
Copyright ยฉ 2024, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on August 23, 2024.
Last updated