You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Javascript module to match a string against a regular expression, glob, string,
or function that takes the string as an argument and returns a truthy or falsy
value. The matcher can also be an array of any or all of these. Useful for
allowing a very flexible user-defined config to define things like file paths.
matchers: (Array|String|RegExp|Function)
String to be directly matched, string with glob patterns, regular expression
test, function that takes the testString as an argument and returns a truthy
value if it should be matched, or an array of any number and mix of these types.
testString: (String|Array) The string to test against the matchers. If
passed as an array, the first element of the array will be used as the
testString for non-function matchers, while the entire array will be applied
as the arguments for function matchers.
options: (Object [optional]_) Any of the picomatch options.
returnIndex: (Boolean [optional]) If true, return the array index of
the first matcher that that testString matched, or -1 if no match, instead of a
boolean result.
constanymatch=require('anymatch');constmatchers=['path/to/file.js','path/anyjs/**/*.js',/foo.js$/,string=>string.includes('bar')&&string.length>10];anymatch(matchers,'path/to/file.js');// trueanymatch(matchers,'path/anyjs/baz.js');// trueanymatch(matchers,'path/to/foo.js');// trueanymatch(matchers,'path/to/bar.js');// trueanymatch(matchers,'bar.js');// false// returnIndex = trueanymatch(matchers,'foo.js',{returnIndex: true});// 2anymatch(matchers,'path/anyjs/foo.js',{returnIndex: true});// 1// any picomatc// using globs to match directories and their childrenanymatch('node_modules','node_modules');// trueanymatch('node_modules','node_modules/somelib/index.js');// falseanymatch('node_modules/**','node_modules/somelib/index.js');// trueanymatch('node_modules/**','/absolute/path/to/node_modules/somelib/index.js');// falseanymatch('**/node_modules/**','/absolute/path/to/node_modules/somelib/index.js');// trueconstmatcher=anymatch(matchers);['foo.js','bar.js'].filter(matcher);// [ 'foo.js' ]anymatchmaster*❯
anymatch(matchers)
You can also pass in only your matcher(s) to get a curried function that has
already been bound to the provided matching criteria. This can be used as an
Array#filter callback.
v1.2: anymatch uses micromatch
for glob pattern matching. Issues with glob pattern matching should be
reported directly to the micromatch issue tracker.