nanomatch
Last updated
Was this helpful?
Last updated
Was this helpful?
Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash 4.3 wildcard support only (no support for exglobs, posix brackets or braces)
Please consider following this project's author, , and consider starring the project to show your and support.
Install with :
Nanomatch is a fast and accurate glob matcher with full support for standard Bash glob features, including the following "metacharacters": *
, **
, ?
and [...]
.
Learn more
Add nanomatch to your project using node's require()
system:
Params
list
{String|Array}: List of strings to perform matches against. This is often a list of file paths.
Examples
Backslashes and quotes can be used to escape characters, forcing nanomatch to regard those characters as a literal characters.
Backslashes
Use backslashes to escape single characters. For example, the following pattern would match foo/*/bar
exactly:
The following pattern would match foo/
followed by a literal *
, followed by zero or more of any characters besides /
, followed by /bar
.
Quoted strings
Use single or double quotes to escape sequences of characters. For example, the following patterns would match foo/**/bar
exactly:
Matching literal quotes
If you need to match quotes literally, you can escape them as well. For example, the following will match foo/"*"/bar
, foo/"a"/bar
, foo/"b"/bar
, or foo/"c"/bar
:
And the following will match foo/'*'/bar
, foo/'a'/bar
, foo/'b'/bar
, or foo/'c'/bar
:
The main function takes a list of strings and one or more glob patterns to use for matching.
Params
list
{Array}: A list of strings to match
patterns
{String|Array}: One or more glob patterns to use for matching.
returns
{Array}: Returns an array of matches
Example
Similar to the main function, but pattern
must be a string.
Params
list
{Array}: Array of strings to match
pattern
{String}: Glob pattern to use for matching.
returns
{Array}: Returns an array of matches
Example
Returns true if the specified string
matches the given glob pattern
.
Params
string
{String}: String to match
pattern
{String}: Glob pattern to use for matching.
returns
{Boolean}: Returns true if the string matches the glob pattern.
Example
Returns true if some of the elements 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.
returns
{Boolean}: Returns true if any patterns match str
Example
Returns true if every element in the given list
matches at least one 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.
returns
{Boolean}: Returns true if any patterns match str
Example
Returns true if any of the given glob 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.
returns
{Boolean}: Returns true if any patterns match str
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.
returns
{Boolean}: Returns true if any patterns match str
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.
returns
{Array}: Returns an array of strings that do not match the given patterns.
Example
Params
str
{String}: The string to match.
patterns
{String|Array}: Glob pattern to use for matching.
returns
{Boolean}: Returns true if the patter matches any part of str
.
Example
Params
object
{Object}: The object with keys to filter.
patterns
{String|Array}: One or more glob patterns to use for matching.
returns
{Object}: Returns an object with only keys that match the given patterns.
Example
Returns a memoized 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
returns
{Function}: Returns a matcher function.
Example
Returns an array of matches captured by pattern
in string, or
null` if the pattern did not match.
Params
pattern
{String}: Glob pattern to use for matching.
string
{String}: String to match
returns
{Boolean}: Returns an array of captures if the string matches the glob pattern, otherwise null
.
Example
Create a regular expression from the given glob pattern
.
Params
pattern
{String}: A glob pattern to convert to regex.
returns
{RegExp}: Returns a regex created from the given pattern.
Example
Parses the given glob pattern
and returns an object with the compiled output
and optional source map
.
Params
pattern
{String}: Glob pattern to parse and compile.
returns
{Object}: Returns an object with the parsed AST, compiled string and optional source map.
Example
Parse the given str
with the given options
.
Params
str
{String}
options
{Object}
returns
{Object}: Returns an AST
Example
Compile the given ast
or string with the given options
.
Params
ast
{Object|String}
options
{Object}
returns
{Object}: Returns an object that has an output
property with the compiled string.
Example
Clear the regex cache.
Example
Nanomatch has full support for standard Bash glob features, including the following "metacharacters": *
, **
, ?
and [...]
.
Here are some examples of how they work:
Pattern
Description
*
Matches any string except for /
, leading .
, or /.
inside a path
**
Matches any string including /
, but not a leading .
or /.
inside a path. More than two stars (e.g. ***
is treated the same as one star, and **
loses its special meaning
foo*
Matches any string beginning with foo
*bar*
Matches any string containing bar
(beginning, middle or end)
*.min.js
Matches any string ending with .min.js
[abc]*.js
Matches any string beginning with a
, b
, or c
and ending with .js
abc?
Matches abcd
or abcz
but not abcde
The exceptions noted for *
apply to all patterns that contain a *
.
Not supported
The following extended-globbing features are not supported:
Related library
Matching Type
Example
Description
nanomatch
(you are here)
Wildcards
*
Tildes
~
Braces
{a,b,c}
Brackets
[[:alpha:]]
Parens
`!(a\
b)`
All
all
Micromatch is built on top of the other libraries.
There are many resources available on the web if you want to dive deeper into how these features work in Bash.
Install dev dependencies:
You might also be interested in these projects:
Commits
Contributor
164
1
Jon Schlinkert
: learn how to install and begin using nanomatch
: jump to info about supported patterns, and a glob matching reference
: jump to available options and methods
: visit unit tests. there is no better way to learn a code library than spending time the unit tests. Nanomatch has 36,000 unit tests - go become a glob matching ninja!
Nanomatch uses for parsing and compiling globs, which results in:
Much greater accuracy than minimatch. In fact, nanomatch passes all of the spec tests from bash, including some that bash still fails. However, since there is no real specification for globs, if you encounter a pattern that yields unexpected match results , .
Nanomatch supports , which is limited to *
, **
, ?
and regex-like brackets.
If you need support for the other (in addition to the wildcard matching provided by nanomatch), consider using instead. (micromatch >=3.0.0 uses the nanomatch parser and compiler for basic glob matching)
Install with
Install with
patterns
{String|Array}: One or more to use for matching.
options
{Object}: Any may be passed
See the for available methods and .
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed
Returns true if the given string
contains the given pattern. Similar to but the pattern can match any part of the string.
options
{Object}: See available for changing how matches are performed
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 instead.
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed.
options
{Object}: See available for changing how matches are performed
options
{Object}: See available for changing how matches are performed.
options
{Object}: Any to change how parsing and compiling is performed.
Allow glob patterns without slashes to match a file path based on its basename. Same behavior as option matchBase
.
Match dotfiles. Same behavior as option dot
.
Alias for .
Use a case-insensitive regex for matching files. Same behavior as .
Alias for .
If true
, when no matches are found the actual (arrayified) glob pattern is returned instead of an empty array. Same behavior as option nonull
.
Pass your own instance of to customize parsers or compilers.
(e.g. {a,b,c}
)
(e.g. @(a|!(c|d))
)
(e.g. [[:alpha:][:digit:]]
)
If you need any of these features consider using instead.
Nanomatch is part of a suite of libraries aimed at bringing the power and expressiveness of matching and expansion capabilities to JavaScript, and - as you can see by the - without sacrificing speed.
, also referred to as globbing and pathname expansion, allows the use of for matching.
converts the leading tilde in a file path to the user home directory.
(also referred to as POSIX brackets, or POSIX character classes)
Pull requests and stars are always welcome. For bugs and feature requests, .
Please read the for advice on opening issues, pull requests, and coding standards.
(This project's readme.md is generated by , please don't edit the readme directly. Any changes to the readme must be made in the readme template.)
: Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… |
: Returns true if a string has an extglob. |
: Returns true
if the given string looks like a glob pattern or an extglob pattern… |
: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. |
Copyright © 2018, . Released under the .
This file was generated by , v0.6.0, on February 18, 2018.