1anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master)
2======
3Javascript module to match a string against a regular expression, glob, string,
4or function that takes the string as an argument and returns a truthy or falsy
5value. The matcher can also be an array of any or all of these. Useful for
6allowing a very flexible user-defined config to define things like file paths.
7
8__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
9
10[![NPM](https://nodei.co/npm/anymatch.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/anymatch/)
11[![NPM](https://nodei.co/npm-dl/anymatch.png?height=3&months=9)](https://nodei.co/npm-dl/anymatch/)
12
13Usage
14-----
15```sh
16npm install anymatch --save
17```
18
19#### anymatch (matchers, testString, [returnIndex], [startIndex], [endIndex])
20* __matchers__: (_Array|String|RegExp|Function_)
21String to be directly matched, string with glob patterns, regular expression
22test, function that takes the testString as an argument and returns a truthy
23value if it should be matched, or an array of any number and mix of these types.
24* __testString__: (_String|Array_) The string to test against the matchers. If
25passed as an array, the first element of the array will be used as the
26`testString` for non-function matchers, while the entire array will be applied
27as the arguments for function matchers.
28* __returnIndex__: (_Boolean [optional]_) If true, return the array index of
29the first matcher that that testString matched, or -1 if no match, instead of a
30boolean result.
31* __startIndex, endIndex__: (_Integer [optional]_) Can be used to define a
32subset out of the array of provided matchers to test against. Can be useful
33with bound matcher functions (see below). When used with `returnIndex = true`
34preserves original indexing. Behaves the same as `Array.prototype.slice` (i.e.
35includes array members up to, but not including endIndex).
36
37```js
38var anymatch = require('anymatch');
39
40var matchers = [
41	'path/to/file.js',
42	'path/anyjs/**/*.js',
43	/foo\.js$/,
44	function (string) {
45		return string.indexOf('bar') !== -1 && string.length > 10
46	}
47];
48
49anymatch(matchers, 'path/to/file.js'); // true
50anymatch(matchers, 'path/anyjs/baz.js'); // true
51anymatch(matchers, 'path/to/foo.js'); // true
52anymatch(matchers, 'path/to/bar.js'); // true
53anymatch(matchers, 'bar.js'); // false
54
55// returnIndex = true
56anymatch(matchers, 'foo.js', true); // 2
57anymatch(matchers, 'path/anyjs/foo.js', true); // 1
58
59// skip matchers
60anymatch(matchers, 'path/to/file.js', false, 1); // false
61anymatch(matchers, 'path/anyjs/foo.js', true, 2, 3); // 2
62anymatch(matchers, 'path/to/bar.js', true, 0, 3); // -1
63
64// using globs to match directories and their children
65anymatch('node_modules', 'node_modules'); // true
66anymatch('node_modules', 'node_modules/somelib/index.js'); // false
67anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
68anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
69anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
70```
71
72#### anymatch (matchers)
73You can also pass in only your matcher(s) to get a curried function that has
74already been bound to the provided matching criteria. This can be used as an
75`Array.prototype.filter` callback.
76
77```js
78var matcher = anymatch(matchers);
79
80matcher('path/to/file.js'); // true
81matcher('path/anyjs/baz.js', true); // 1
82matcher('path/anyjs/baz.js', true, 2); // -1
83
84['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
85```
86
87Change Log
88----------
89[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
90
91NOTE: As of v2.0.0, [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
92
93NOTE: As of v1.2.0, anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
94for glob pattern matching. Issues with glob pattern matching should be
95reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
96
97License
98-------
99[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)
100