micromatch 2.3.11 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of micromatch might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,12 +1,54 @@
1
- # micromatch [![NPM version](https://img.shields.io/npm/v/micromatch.svg?style=flat)](https://www.npmjs.com/package/micromatch) [![NPM downloads](https://img.shields.io/npm/dm/micromatch.svg?style=flat)](https://npmjs.org/package/micromatch) [![Build Status](https://img.shields.io/travis/jonschlinkert/micromatch.svg?style=flat)](https://travis-ci.org/jonschlinkert/micromatch)
1
+ # micromatch [![NPM version](https://img.shields.io/npm/v/micromatch.svg?style=flat)](https://www.npmjs.com/package/micromatch) [![NPM monthly downloads](https://img.shields.io/npm/dm/micromatch.svg?style=flat)](https://npmjs.org/package/micromatch) [![NPM total downloads](https://img.shields.io/npm/dt/micromatch.svg?style=flat)](https://npmjs.org/package/micromatch) [![Linux Build Status](https://img.shields.io/travis/micromatch/micromatch.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/micromatch) [![Windows Build Status](https://img.shields.io/appveyor/ci/micromatch/micromatch.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/micromatch/micromatch)
2
2
 
3
3
  > Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.
4
4
 
5
- Micromatch supports all of the same matching features as [minimatch](https://github.com/isaacs/minimatch) and [multimatch](https://github.com/sindresorhus/multimatch).
6
-
7
- * [mm()](#usage) is the same as [multimatch()](https://github.com/sindresorhus/multimatch)
8
- * [mm.match()](#match) is the same as [minimatch.match()](https://github.com/isaacs/minimatch)
9
- * use [mm.isMatch()](#ismatch) instead of [minimatch()](https://github.com/isaacs/minimatch)
5
+ <details>
6
+ <summary><strong>Table of Contents</strong></summary>
7
+
8
+ - [Install](#install)
9
+ - [Quickstart](#quickstart)
10
+ - [Why use micromatch?](#why-use-micromatch)
11
+ * [Matching features](#matching-features)
12
+ - [Switching to micromatch](#switching-to-micromatch)
13
+ * [From minimatch](#from-minimatch)
14
+ * [From multimatch](#from-multimatch)
15
+ - [API](#api)
16
+ - [Options](#options)
17
+ * [options.basename](#optionsbasename)
18
+ * [options.bash](#optionsbash)
19
+ * [options.cache](#optionscache)
20
+ * [options.dot](#optionsdot)
21
+ * [options.failglob](#optionsfailglob)
22
+ * [options.ignore](#optionsignore)
23
+ * [options.matchBase](#optionsmatchbase)
24
+ * [options.nobrace](#optionsnobrace)
25
+ * [options.nocase](#optionsnocase)
26
+ * [options.nodupes](#optionsnodupes)
27
+ * [options.noext](#optionsnoext)
28
+ * [options.nonegate](#optionsnonegate)
29
+ * [options.noglobstar](#optionsnoglobstar)
30
+ * [options.nonull](#optionsnonull)
31
+ * [options.nullglob](#optionsnullglob)
32
+ * [options.snapdragon](#optionssnapdragon)
33
+ * [options.sourcemap](#optionssourcemap)
34
+ * [options.unescape](#optionsunescape)
35
+ * [options.unixify](#optionsunixify)
36
+ - [Extended globbing](#extended-globbing)
37
+ * [extglobs](#extglobs)
38
+ * [braces](#braces)
39
+ * [regex character classes](#regex-character-classes)
40
+ * [regex groups](#regex-groups)
41
+ * [POSIX bracket expressions](#posix-bracket-expressions)
42
+ - [Notes](#notes)
43
+ * [Bash 4.3 parity](#bash-43-parity)
44
+ * [Backslashes](#backslashes)
45
+ - [Contributing](#contributing)
46
+ - [Benchmarks](#benchmarks)
47
+ * [Running benchmarks](#running-benchmarks)
48
+ * [Latest results](#latest-results)
49
+ - [About](#about)
50
+
51
+ </details>
10
52
 
11
53
  ## Install
12
54
 
@@ -16,65 +58,75 @@ Install with [npm](https://www.npmjs.com/):
16
58
  $ npm install --save micromatch
17
59
  ```
18
60
 
19
- ## Start matching!
61
+ ## Quickstart
20
62
 
21
63
  ```js
22
64
  var mm = require('micromatch');
23
- console.log(mm(['']))
65
+ mm(list, patterns[, options]);
24
66
  ```
25
67
 
26
- ***
68
+ The [main export](#micromatch) takes a list of strings and one or more glob patterns:
27
69
 
28
- ### Features
70
+ ```js
71
+ console.log(mm(['foo', 'bar', 'qux'], ['f*', 'b*']));
72
+ //=> ['foo', 'bar']
73
+ ```
29
74
 
30
- * [Drop-in replacement](#switch-from-minimatch) for [minimatch](https://github.com/isaacs/minimatch) and [multimatch](https://github.com/sindresorhus/multimatch)
31
- * Built-in support for multiple glob patterns, like `['foo/*.js', '!bar.js']`
32
- * [Brace Expansion](https://github.com/jonschlinkert/braces) (`foo/bar-{1..5}.md`, `one/{two,three}/four.md`)
33
- * Typical glob patterns, like `**/*`, `a/b/*.js`, or `['foo/*.js', '!bar.js']`
34
- * Methods like `.isMatch()`, `.contains()` and `.any()`
75
+ Use [.isMatch()](#ismatch) to get true/false:
35
76
 
36
- **Extended globbing features:**
77
+ ```js
78
+ console.log(mm.isMatch('foo', 'f*'));
79
+ //=> true
80
+ ```
37
81
 
38
- * Logical `OR` (`foo/bar/(abc|xyz).js`)
39
- * Regex character classes (`foo/bar/baz-[1-5].js`)
40
- * POSIX [bracket expressions](https://github.com/jonschlinkert/expand-brackets) (`**/[[:alpha:][:digit:]]/`)
41
- * [extglobs](https://github.com/jonschlinkert/extglob) (`**/+(x|y)`, `!(a|b)`, etc).
82
+ [Switching](#switching-to-micromatch) from minimatch and multimatch is easy!
42
83
 
43
- You can combine these to create whatever matching patterns you need.
84
+ ## Why use micromatch?
44
85
 
45
- **Example**
86
+ > micromatch is a [drop-in replacement](#switching-to-micromatch) for minimatch and multimatch
46
87
 
47
- ```js
48
- // double-negation!
49
- mm(['fa', 'fb', 'f', 'fo'], '!(f!(o))');
50
- //=> ['fo']
51
- ```
88
+ * Supports all of the same matching features as [minimatch](https://github.com/isaacs/minimatch) and [multimatch](https://github.com/sindresorhus/multimatch)
89
+ * Micromatch uses [snapdragon](https://github.com/jonschlinkert/snapdragon) for parsing and compiling globs, which provides granular control over the entire conversion process in a way that is easy to understand, reason about, and maintain.
90
+ * More consistently accurate matching [than minimatch](https://github.com/yarnpkg/yarn/pull/3339), with more than 36,000 [test assertions](./test) to prove it.
91
+ * More complete support for the Bash 4.3 specification than minimatch and multimatch. In fact, micromatch passes _all of the spec tests_ from bash, including some that bash still fails.
92
+ * [Faster matching](#benchmarks), from a combination of optimized glob patterns, faster algorithms, and regex caching.
93
+ * [Micromatch is safer](https://github.com/micromatch/braces#braces-is-safe), and is not subject to DoS with brace patterns, like minimatch and multimatch.
94
+ * More reliable windows support than minimatch and multimatch.
95
+
96
+ ### Matching features
97
+
98
+ * Support for multiple glob patterns (no need for wrappers like multimatch)
99
+ * Wildcards (`**`, `*.js`)
100
+ * Negation (`'!a/*.js'`, `'*!(b).js']`)
101
+ * [extglobs](https://github.com/jonschlinkert/extglob) (`+(x|y)`, `!(a|b)`)
102
+ * [POSIX character classes](https://github.com/micromatch/expand-brackets) (`[[:alpha:][:digit:]]`)
103
+ * [brace expansion](https://github.com/micromatch/braces) (`foo/{1..5}.md`, `bar/{a,b,c}.js`)
104
+ * regex character classes (`foo-[1-5].js`)
105
+ * regex logical "or" (`foo/(abc|xyz).js`)
52
106
 
53
- ## Why switch to micromatch?
107
+ You can mix and match these features to create whatever patterns you need!
54
108
 
55
- * Native support for multiple glob patterns, no need for wrappers like [multimatch](https://github.com/sindresorhus/multimatch)
56
- * [10-55x faster](#benchmarks) and more performant than [minimatch](https://github.com/isaacs/minimatch) and [multimatch](https://github.com/sindresorhus/multimatch). This is achieved through a combination of caching and regex optimization strategies, a fundamentally different approach than minimatch.
57
- * More extensive support for the Bash 4.3 specification
58
- * More complete extglob support
59
- * Extensive [unit tests](./test) (approx. 1,300 tests). Minimatch fails many of the tests.
109
+ ## Switching to micromatch
60
110
 
61
- ### Switch from minimatch
111
+ There is one notable difference between micromatch and minimatch in regards to how backslashes are handled. See [the notes about backslashes](#backslashes) for more information.
62
112
 
63
- Use `mm.isMatch()` instead of `minimatch()`:
113
+ ### From minimatch
114
+
115
+ Use [mm.isMatch()](#ismatch) instead of `minimatch()`:
64
116
 
65
117
  ```js
66
118
  mm.isMatch('foo', 'b*');
67
119
  //=> false
68
120
  ```
69
121
 
70
- Use `mm.match()` instead of `minimatch.match()`:
122
+ Use [mm.match()](#match) instead of `minimatch.match()`:
71
123
 
72
124
  ```js
73
125
  mm.match(['foo', 'bar'], 'b*');
74
126
  //=> 'bar'
75
127
  ```
76
128
 
77
- ### Switch from multimatch
129
+ ### From multimatch
78
130
 
79
131
  Same signature:
80
132
 
@@ -83,436 +135,733 @@ mm(['foo', 'bar', 'baz'], ['f*', '*z']);
83
135
  //=> ['foo', 'baz']
84
136
  ```
85
137
 
86
- ***
138
+ ## API
87
139
 
88
- ## Usage
140
+ ### [micromatch](index.js#L41)
89
141
 
90
- Add micromatch to your node.js project:
142
+ The main function takes a list of strings and one or more glob patterns to use for matching.
143
+
144
+ **Params**
145
+
146
+ * `list` **{Array}**: A list of strings to match
147
+ * `patterns` **{String|Array}**: One or more glob patterns to use for matching.
148
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
149
+ * `returns` **{Array}**: Returns an array of matches
150
+
151
+ **Example**
91
152
 
92
153
  ```js
93
154
  var mm = require('micromatch');
155
+ mm(list, patterns[, options]);
156
+
157
+ console.log(mm(['a.js', 'a.txt'], ['*.js']));
158
+ //=> [ 'a.js' ]
94
159
  ```
95
160
 
96
- **Signature**
161
+ ### [.match](index.js#L95)
97
162
 
98
- ```js
99
- mm(array_of_strings, glob_patterns[, options]);
100
- ```
163
+ Similar to the main function, but `pattern` must be a string.
164
+
165
+ **Params**
166
+
167
+ * `list` **{Array}**: Array of strings to match
168
+ * `pattern` **{String}**: Glob pattern to use for matching.
169
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
170
+ * `returns` **{Array}**: Returns an array of matches
101
171
 
102
172
  **Example**
103
173
 
104
174
  ```js
105
- mm(['foo', 'bar', 'baz'], 'b*');
106
- //=> ['bar', 'baz']
175
+ var mm = require('micromatch');
176
+ mm.match(list, pattern[, options]);
177
+
178
+ console.log(mm.match(['a.a', 'a.aa', 'a.b', 'a.c'], '*.a'));
179
+ //=> ['a.a', 'a.aa']
107
180
  ```
108
181
 
109
- ### Usage examples
182
+ ### [.isMatch](index.js#L156)
183
+
184
+ Returns true if the specified `string` matches the given glob `pattern`.
185
+
186
+ **Params**
110
187
 
111
- **Brace expansion**
188
+ * `string` **{String}**: String to match
189
+ * `pattern` **{String}**: Glob pattern to use for matching.
190
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
191
+ * `returns` **{Boolean}**: Returns true if the string matches the glob pattern.
112
192
 
113
- Match files with `.js` or `.txt` extensions.
193
+ **Example**
114
194
 
115
195
  ```js
116
- mm(['a.js', 'b.md', 'c.txt'], '*.{js,txt}');
117
- //=> ['a.js', 'c.txt']
196
+ var mm = require('micromatch');
197
+ mm.isMatch(string, pattern[, options]);
198
+
199
+ console.log(mm.isMatch('a.a', '*.a'));
200
+ //=> true
201
+ console.log(mm.isMatch('a.b', '*.a'));
202
+ //=> false
118
203
  ```
119
204
 
120
- **Extglobs**
205
+ ### [.some](index.js#L194)
121
206
 
122
- Match anything except for files with the `.md` extension.
207
+ Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
208
+
209
+ **Params**
210
+
211
+ * `list` **{String|Array}**: The string or array of strings to test. Returns as soon as the first match is found.
212
+ * `patterns` **{String|Array}**: One or more glob patterns to use for matching.
213
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
214
+ * `returns` **{Boolean}**: Returns true if any patterns match `str`
215
+
216
+ **Example**
123
217
 
124
218
  ```js
125
- mm(files, '**/*.!(md)');
219
+ var mm = require('micromatch');
220
+ mm.some(list, patterns[, options]);
126
221
 
127
- //=> ['a.js', 'c.txt']
222
+ console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
223
+ // true
224
+ console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
225
+ // false
128
226
  ```
129
227
 
130
- **Multiple patterns**
228
+ ### [.every](index.js#L230)
229
+
230
+ Returns true if every string in the given `list` matches any of the given glob `patterns`.
231
+
232
+ **Params**
131
233
 
132
- Match using an array of patterns.
234
+ * `list` **{String|Array}**: The string or array of strings to test.
235
+ * `patterns` **{String|Array}**: One or more glob patterns to use for matching.
236
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
237
+ * `returns` **{Boolean}**: Returns true if any patterns match `str`
238
+
239
+ **Example**
133
240
 
134
241
  ```js
135
- mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.md', '*.txt']);
136
- //=> ['a.md', 'c.txt']
242
+ var mm = require('micromatch');
243
+ mm.every(list, patterns[, options]);
244
+
245
+ console.log(mm.every('foo.js', ['foo.js']));
246
+ // true
247
+ console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
248
+ // true
249
+ console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
250
+ // false
251
+ console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
252
+ // false
137
253
  ```
138
254
 
139
- **Negation patterns:**
255
+ ### [.any](index.js#L262)
140
256
 
141
- Behavior is designed to be what users would expect, based on conventions that are already well-established.
257
+ Returns true if **any** of the given glob `patterns` match the specified `string`.
142
258
 
143
- * [minimatch](https://github.com/isaacs/minimatch) behavior is used when the pattern is a string, so patterns are **inclusive by default**.
144
- * [multimatch](https://github.com/sindresorhus/multimatch) behavior is used when an array of patterns is passed, so patterns are **exclusive by default**.
259
+ **Params**
260
+
261
+ * `str` **{String|Array}**: The string to test.
262
+ * `patterns` **{String|Array}**: One or more glob patterns to use for matching.
263
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
264
+ * `returns` **{Boolean}**: Returns true if any patterns match `str`
265
+
266
+ **Example**
145
267
 
146
268
  ```js
147
- mm(['a.js', 'b.md', 'c.txt'], '!*.{js,txt}');
148
- //=> ['b.md']
269
+ var mm = require('micromatch');
270
+ mm.any(string, patterns[, options]);
149
271
 
150
- mm(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.*', '!*.{js,txt}']);
151
- //=> ['a.md', 'd.json']
272
+ console.log(mm.any('a.a', ['b.*', '*.a']));
273
+ //=> true
274
+ console.log(mm.any('a.a', 'b.*'));
275
+ //=> false
152
276
  ```
153
277
 
154
- ***
278
+ ### [.all](index.js#L310)
279
+
280
+ Returns true if **all** of the given `patterns` match the specified string.
281
+
282
+ **Params**
155
283
 
156
- ## API methods
284
+ * `str` **{String|Array}**: The string to test.
285
+ * `patterns` **{String|Array}**: One or more glob patterns to use for matching.
286
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
287
+ * `returns` **{Boolean}**: Returns true if any patterns match `str`
288
+
289
+ **Example**
157
290
 
158
291
  ```js
159
292
  var mm = require('micromatch');
160
- ```
293
+ mm.all(string, patterns[, options]);
161
294
 
162
- ### .match
295
+ console.log(mm.all('foo.js', ['foo.js']));
296
+ // true
163
297
 
164
- ```js
165
- mm.match(array, globString);
298
+ console.log(mm.all('foo.js', ['*.js', '!foo.js']));
299
+ // false
300
+
301
+ console.log(mm.all('foo.js', ['*.js', 'foo.js']));
302
+ // true
303
+
304
+ console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
305
+ // true
166
306
  ```
167
307
 
168
- Return an array of files that match the given glob pattern. Useful if you only need to use a single glob pattern.
308
+ ### [.not](index.js#L342)
309
+
310
+ Returns a list of strings that _**do not match any**_ of the given `patterns`.
311
+
312
+ **Params**
313
+
314
+ * `list` **{Array}**: Array of strings to match.
315
+ * `patterns` **{String|Array}**: One or more glob pattern to use for matching.
316
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
317
+ * `returns` **{Array}**: Returns an array of strings that **do not match** the given patterns.
169
318
 
170
319
  **Example**
171
320
 
172
321
  ```js
173
- mm.match(['ab', 'a/b', 'bb', 'b/c'], '?b');
174
- //=> ['ab', 'bb']
322
+ var mm = require('micromatch');
323
+ mm.not(list, patterns[, options]);
175
324
 
176
- mm.match(['ab', 'a/b', 'bb', 'b/c'], '*/b');
177
- //=> ['a/b']
325
+ console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
326
+ //=> ['b.b', 'c.c']
178
327
  ```
179
328
 
180
- ### .isMatch
329
+ ### [.contains](index.js#L377)
181
330
 
182
- ```js
183
- mm.isMatch(filepath, globString);
184
- ```
331
+ Returns true if the given `string` contains the given pattern. Similar to [.isMatch](#isMatch) but the pattern can match any part of the string.
185
332
 
186
- Returns true if a file path matches the given glob pattern.
333
+ **Params**
334
+
335
+ * `str` **{String}**: The string to match.
336
+ * `patterns` **{String|Array}**: Glob pattern to use for matching.
337
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
338
+ * `returns` **{Boolean}**: Returns true if the patter matches any part of `str`.
187
339
 
188
340
  **Example**
189
341
 
190
342
  ```js
191
- mm.isMatch('.verb.md', '*.md');
192
- //=> false
343
+ var mm = require('micromatch');
344
+ mm.contains(string, pattern[, options]);
193
345
 
194
- mm.isMatch('.verb.md', '*.md', {dot: true});
346
+ console.log(mm.contains('aa/bb/cc', '*b'));
195
347
  //=> true
348
+ console.log(mm.contains('aa/bb/cc', '*d'));
349
+ //=> false
196
350
  ```
197
351
 
198
- ### .contains
352
+ ### [.matchKeys](index.js#L433)
199
353
 
200
- Returns true if any part of a file path matches the given glob pattern. Think of this is "has path" versus "is path".
354
+ 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](https://github.com/jonschlinkert/glob-object) instead.
201
355
 
202
- **Example**
356
+ **Params**
357
+
358
+ * `object` **{Object}**: The object with keys to filter.
359
+ * `patterns` **{String|Array}**: One or more glob patterns to use for matching.
360
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
361
+ * `returns` **{Object}**: Returns an object with only keys that match the given patterns.
203
362
 
204
- `.isMatch()` would return false for both of the following:
363
+ **Example**
205
364
 
206
365
  ```js
207
- mm.contains('a/b/c', 'a/b');
208
- //=> true
366
+ var mm = require('micromatch');
367
+ mm.matchKeys(object, patterns[, options]);
209
368
 
210
- mm.contains('a/b/c', 'a/*');
211
- //=> true
369
+ var obj = { aa: 'a', ab: 'b', ac: 'c' };
370
+ console.log(mm.matchKeys(obj, '*b'));
371
+ //=> { ab: 'b' }
212
372
  ```
213
373
 
214
- ### .matcher
374
+ ### [.matcher](index.js#L462)
215
375
 
216
- Returns a function for matching using the supplied pattern. e.g. create your own "matcher". The advantage of this method is that the pattern can be compiled outside of a loop.
376
+ 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.
217
377
 
218
- **Pattern**
219
-
220
- Can be any of the following:
378
+ **Params**
221
379
 
222
- * `glob/string`
223
- * `regex`
224
- * `function`
380
+ * `pattern` **{String}**: Glob pattern
381
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed.
382
+ * `returns` **{Function}**: Returns a matcher function.
225
383
 
226
384
  **Example**
227
385
 
228
386
  ```js
229
- var isMatch = mm.matcher('*.md');
230
- var files = [];
387
+ var mm = require('micromatch');
388
+ mm.matcher(pattern[, options]);
231
389
 
232
- ['a.md', 'b.txt', 'c.md'].forEach(function(fp) {
233
- if (isMatch(fp)) {
234
- files.push(fp);
235
- }
236
- });
390
+ var isMatch = mm.matcher('*.!(*a)');
391
+ console.log(isMatch('a.a'));
392
+ //=> false
393
+ console.log(isMatch('a.b'));
394
+ //=> true
237
395
  ```
238
396
 
239
- ### .filter
397
+ ### [.makeRe](index.js#L534)
240
398
 
241
- Returns a function that can be passed to `Array#filter()`.
399
+ Create a regular expression from the given glob `pattern`.
242
400
 
243
401
  **Params**
244
402
 
245
- * `patterns` **{String|Array}**:
246
-
247
- **Examples**
403
+ * `pattern` **{String}**: A glob pattern to convert to regex.
404
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed.
405
+ * `returns` **{RegExp}**: Returns a regex created from the given pattern.
248
406
 
249
- Single glob:
407
+ **Example**
250
408
 
251
409
  ```js
252
- var fn = mm.filter('*.md');
253
- ['a.js', 'b.txt', 'c.md'].filter(fn);
254
- //=> ['c.md']
410
+ var mm = require('micromatch');
411
+ mm.makeRe(pattern[, options]);
255
412
 
256
- var fn = mm.filter('[a-c]');
257
- ['a', 'b', 'c', 'd', 'e'].filter(fn);
258
- //=> ['a', 'b', 'c']
413
+ console.log(mm.makeRe('*.js'));
414
+ //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
259
415
  ```
260
416
 
261
- Array of glob patterns:
417
+ ### [.braces](index.js#L581)
418
+
419
+ Expand the given brace `pattern`.
420
+
421
+ **Params**
422
+
423
+ * `pattern` **{String}**: String with brace pattern to expand.
424
+ * `options` **{Object}**: Any [options](#options) to change how expansion is performed. See the [braces](https://github.com/micromatch/braces) library for all available options.
425
+ * `returns` **{Array}**
426
+
427
+ **Example**
262
428
 
263
429
  ```js
264
- var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
430
+ var mm = require('micromatch');
431
+ console.log(mm.braces('foo/{a,b}/bar'));
432
+ //=> ['foo/(a|b)/bar']
265
433
 
266
- var fn = mm.filter(['{1..10}', '![7-9]', '!{3..4}']);
267
- arr.filter(fn);
268
- //=> [1, 2, 5, 6, 10]
434
+ console.log(mm.braces('foo/{a,b}/bar', {expand: true}));
435
+ //=> ['foo/(a|b)/bar']
269
436
  ```
270
437
 
271
- _(Internally this function generates the matching function by using the [matcher](#matcher) method. You can use the [matcher](#matcher) method directly to create your own filter function)_
438
+ ### [.create](index.js#L648)
439
+
440
+ Parses the given glob `pattern` and returns an array of abstract syntax trees (ASTs), with the compiled `output` and optional source `map` on each AST.
272
441
 
273
- ### .any
442
+ **Params**
274
443
 
275
- Returns true if a file path matches any of the given patterns.
444
+ * `pattern` **{String}**: Glob pattern to parse and compile.
445
+ * `options` **{Object}**: Any [options](#options) to change how parsing and compiling is performed.
446
+ * `returns` **{Object}**: Returns an object with the parsed AST, compiled string and optional source map.
447
+
448
+ **Example**
276
449
 
277
450
  ```js
278
- mm.any(filepath, patterns, options);
451
+ var mm = require('micromatch');
452
+ mm.create(pattern[, options]);
453
+
454
+ console.log(mm.create('abc/*.js'));
455
+ // [{ options: { source: 'string', sourcemap: true },
456
+ // state: {},
457
+ // compilers:
458
+ // { ... },
459
+ // output: '(\\.[\\\\\\/])?abc\\/(?!\\.)(?=.)[^\\/]*?\\.js',
460
+ // ast:
461
+ // { type: 'root',
462
+ // errors: [],
463
+ // nodes:
464
+ // [ ... ],
465
+ // dot: false,
466
+ // input: 'abc/*.js' },
467
+ // parsingErrors: [],
468
+ // map:
469
+ // { version: 3,
470
+ // sources: [ 'string' ],
471
+ // names: [],
472
+ // mappings: 'AAAA,GAAG,EAAC,kBAAC,EAAC,EAAE',
473
+ // sourcesContent: [ 'abc/*.js' ] },
474
+ // position: { line: 1, column: 28 },
475
+ // content: {},
476
+ // files: {},
477
+ // idx: 6 }]
279
478
  ```
280
479
 
480
+ ### [.parse](index.js#L695)
481
+
482
+ Parse the given `str` with the given `options`.
483
+
281
484
  **Params**
282
485
 
283
- * filepath `{String}`: The file path to test.
284
- * patterns `{String|Array}`: One or more glob patterns
285
- * options: `{Object}`: options to pass to the `.matcher()` method.
486
+ * `str` **{String}**
487
+ * `options` **{Object}**
488
+ * `returns` **{Object}**: Returns an AST
286
489
 
287
490
  **Example**
288
491
 
289
492
  ```js
290
- mm.any('abc', ['!*z']);
291
- //=> true
292
- mm.any('abc', ['a*', 'z*']);
293
- //=> true
294
- mm.any('abc', 'a*');
295
- //=> true
296
- mm.any('abc', ['z*']);
297
- //=> false
493
+ var mm = require('micromatch');
494
+ mm.parse(pattern[, options]);
495
+
496
+ var ast = mm.parse('a/{b,c}/d');
497
+ console.log(ast);
498
+ // { type: 'root',
499
+ // errors: [],
500
+ // input: 'a/{b,c}/d',
501
+ // nodes:
502
+ // [ { type: 'bos', val: '' },
503
+ // { type: 'text', val: 'a/' },
504
+ // { type: 'brace',
505
+ // nodes:
506
+ // [ { type: 'brace.open', val: '{' },
507
+ // { type: 'text', val: 'b,c' },
508
+ // { type: 'brace.close', val: '}' } ] },
509
+ // { type: 'text', val: '/d' },
510
+ // { type: 'eos', val: '' } ] }
298
511
  ```
299
512
 
300
- ### .expand
513
+ ### [.compile](index.js#L748)
301
514
 
302
- Returns an object with a regex-compatible string and tokens.
515
+ Compile the given `ast` or string with the given `options`.
303
516
 
304
- ```js
305
- mm.expand('*.js');
306
-
307
- // when `track` is enabled (for debugging), the `history` array is used
308
- // to record each mutation to the glob pattern as it's converted to regex
309
- { options: { track: false, dot: undefined, makeRe: true, negated: false },
310
- pattern: '(.*\\/|^)bar\\/(?:(?!(?:^|\\/)\\.).)*?',
311
- history: [],
312
- tokens:
313
- { path:
314
- { whole: '**/bar/**',
315
- dirname: '**/bar/',
316
- filename: '**',
317
- basename: '**',
318
- extname: '',
319
- ext: '' },
320
- is:
321
- { glob: true,
322
- negated: false,
323
- globstar: true,
324
- dotfile: false,
325
- dotdir: false },
326
- match: {},
327
- original: '**/bar/**',
328
- pattern: '**/bar/**',
329
- base: '' } }
330
- ```
331
-
332
- ### .makeRe
333
-
334
- Create a regular expression for matching file paths based on the given pattern:
517
+ **Params**
518
+
519
+ * `ast` **{Object|String}**
520
+ * `options` **{Object}**
521
+ * `returns` **{Object}**: Returns an object that has an `output` property with the compiled string.
522
+
523
+ **Example**
335
524
 
336
525
  ```js
337
- mm.makeRe('*.js');
338
- //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
526
+ var mm = require('micromatch');
527
+ mm.compile(ast[, options]);
528
+
529
+ var ast = mm.parse('a/{b,c}/d');
530
+ console.log(mm.compile(ast));
531
+ // { options: { source: 'string' },
532
+ // state: {},
533
+ // compilers:
534
+ // { eos: [Function],
535
+ // noop: [Function],
536
+ // bos: [Function],
537
+ // brace: [Function],
538
+ // 'brace.open': [Function],
539
+ // text: [Function],
540
+ // 'brace.close': [Function] },
541
+ // output: [ 'a/(b|c)/d' ],
542
+ // ast:
543
+ // { ... },
544
+ // parsingErrors: [] }
339
545
  ```
340
546
 
341
- ## Options
547
+ ### [.clearCache](index.js#L769)
342
548
 
343
- ### options.unixify
549
+ Clear the regex cache.
344
550
 
345
- Normalize slashes in file paths and glob patterns to forward slashes.
551
+ **Example**
346
552
 
347
- Type: `{Boolean}`
553
+ ```js
554
+ mm.clearCache();
555
+ ```
348
556
 
349
- Default: `undefined` on non-windows, `true` on windows.
557
+ ## Options
350
558
 
351
- ### options.dot
559
+ * [basename](#optionsbasename)
560
+ * [bash](#optionsbash)
561
+ * [cache](#optionscache)
562
+ * [dot](#optionsdot)
563
+ * [failglob](#optionsfailglob)
564
+ * [ignore](#optionsignore)
565
+ * [matchBase](#optionsmatchBase)
566
+ * [nobrace](#optionsnobrace)
567
+ * [nocase](#optionsnocase)
568
+ * [nodupes](#optionsnodupes)
569
+ * [noext](#optionsnoext)
570
+ * [noglobstar](#optionsnoglobstar)
571
+ * [nonull](#optionsnonull)
572
+ * [nullglob](#optionsnullglob)
573
+ * [snapdragon](#optionssnapdragon)
574
+ * [sourcemap](#optionssourcemap)
575
+ * [unescape](#optionsunescape)
576
+ * [unixify](#optionsunixify)
577
+
578
+ ### options.basename
579
+
580
+ Allow glob patterns without slashes to match a file path based on its basename. Same behavior as [minimatch](https://github.com/isaacs/minimatch) option `matchBase`.
581
+
582
+ **Type**: `Boolean`
583
+
584
+ **Default**: `false`
352
585
 
353
- Match dotfiles. Same behavior as [minimatch](https://github.com/isaacs/minimatch).
586
+ **Example**
354
587
 
355
- Type: `{Boolean}`
588
+ ```js
589
+ mm(['a/b.js', 'a/c.md'], '*.js');
590
+ //=> []
356
591
 
357
- Default: `false`
592
+ mm(['a/b.js', 'a/c.md'], '*.js', {matchBase: true});
593
+ //=> ['a/b.js']
594
+ ```
358
595
 
359
- ### options.unescape
596
+ ### options.bash
360
597
 
361
- Unescape slashes in glob patterns. Use cautiously, especially on windows.
598
+ 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.
362
599
 
363
- Type: `{Boolean}`
600
+ **Type**: `Boolean`
364
601
 
365
- Default: `undefined`
602
+ **Default**: `true`
366
603
 
367
604
  **Example**
368
605
 
369
606
  ```js
370
- mm.isMatch('abc', '\\a\\b\\c', {unescape: true});
371
- //=> true
607
+ var files = ['abc', 'ajz'];
608
+ console.log(mm(files, '[a-c]*'));
609
+ //=> ['abc', 'ajz']
610
+
611
+ console.log(mm(files, '[a-c]*', {bash: false}));
372
612
  ```
373
613
 
614
+ ### options.cache
615
+
616
+ Disable regex and function memoization.
617
+
618
+ **Type**: `Boolean`
619
+
620
+ **Default**: `undefined`
621
+
622
+ ### options.dot
623
+
624
+ Match dotfiles. Same behavior as [minimatch](https://github.com/isaacs/minimatch) option `dot`.
625
+
626
+ **Type**: `Boolean`
627
+
628
+ **Default**: `false`
629
+
630
+ ### options.failglob
631
+
632
+ Similar to the `--failglob` behavior in Bash, throws an error when no matches are found.
633
+
634
+ **Type**: `Boolean`
635
+
636
+ **Default**: `undefined`
637
+
638
+ ### options.ignore
639
+
640
+ String or array of glob patterns to match files to ignore.
641
+
642
+ **Type**: `String|Array`
643
+
644
+ **Default**: `undefined`
645
+
646
+ ### options.matchBase
647
+
648
+ Alias for [options.basename](#options-basename).
649
+
650
+ ### options.nobrace
651
+
652
+ Disable expansion of brace patterns. Same behavior as [minimatch](https://github.com/isaacs/minimatch) option `nobrace`.
653
+
654
+ **Type**: `Boolean`
655
+
656
+ **Default**: `undefined`
657
+
658
+ See [braces](https://github.com/micromatch/braces) for more information about extended brace expansion.
659
+
660
+ ### options.nocase
661
+
662
+ Use a case-insensitive regex for matching files. Same behavior as [minimatch](https://github.com/isaacs/minimatch).
663
+
664
+ **Type**: `Boolean`
665
+
666
+ **Default**: `undefined`
667
+
374
668
  ### options.nodupes
375
669
 
376
670
  Remove duplicate elements from the result array.
377
671
 
378
- Type: `{Boolean}`
672
+ **Type**: `Boolean`
379
673
 
380
- Default: `undefined`
674
+ **Default**: `undefined`
381
675
 
382
676
  **Example**
383
677
 
384
678
  Example of using the `unescape` and `nodupes` options together:
385
679
 
386
680
  ```js
387
- mm.match(['abc', '\\a\\b\\c'], '\\a\\b\\c', {unescape: true});
388
- //=> ['abc', 'abc']
681
+ mm.match(['a/b/c', 'a/b/c'], 'a/b/c');
682
+ //=> ['a/b/c', 'a/b/c']
389
683
 
390
- mm.match(['abc', '\\a\\b\\c'], '\\a\\b\\c', {unescape: true, nodupes: true});
684
+ mm.match(['a/b/c', 'a/b/c'], 'a/b/c', {nodupes: true});
391
685
  //=> ['abc']
392
686
  ```
393
687
 
394
- ### options.matchBase
688
+ ### options.noext
395
689
 
396
- Allow glob patterns without slashes to match a file path based on its basename. . Same behavior as [minimatch](https://github.com/isaacs/minimatch).
690
+ Disable extglob support, so that extglobs are regarded as literal characters.
397
691
 
398
- Type: `{Boolean}`
692
+ **Type**: `Boolean`
399
693
 
400
- Default: `false`
694
+ **Default**: `undefined`
401
695
 
402
- **Example**
696
+ **Examples**
403
697
 
404
698
  ```js
405
- mm(['a/b.js', 'a/c.md'], '*.js');
406
- //=> []
699
+ mm(['a/z', 'a/b', 'a/!(z)'], 'a/!(z)');
700
+ //=> ['a/b', 'a/!(z)']
407
701
 
408
- mm(['a/b.js', 'a/c.md'], '*.js', {matchBase: true});
409
- //=> ['a/b.js']
702
+ mm(['a/z', 'a/b', 'a/!(z)'], 'a/!(z)', {noext: true});
703
+ //=> ['a/!(z)'] (matches only as literal characters)
410
704
  ```
411
705
 
412
- ### options.nobraces
706
+ ### options.nonegate
413
707
 
414
- Don't expand braces in glob patterns. Same behavior as [minimatch](https://github.com/isaacs/minimatch) `nobrace`.
708
+ Disallow negation (`!`) patterns, and treat leading `!` as a literal character to match.
415
709
 
416
- Type: `{Boolean}`
710
+ **Type**: `Boolean`
417
711
 
418
- Default: `undefined`
712
+ **Default**: `undefined`
419
713
 
420
- See [braces](https://github.com/jonschlinkert/braces) for more information about extended brace expansion.
714
+ ### options.noglobstar
421
715
 
422
- ### options.nobrackets
716
+ Disable matching with globstars (`**`).
423
717
 
424
- Don't expand POSIX bracket expressions.
718
+ **Type**: `Boolean`
425
719
 
426
- Type: `{Boolean}`
720
+ **Default**: `undefined`
427
721
 
428
- Default: `undefined`
722
+ ```js
723
+ mm(['a/b', 'a/b/c', 'a/b/c/d'], 'a/**');
724
+ //=> ['a/b', 'a/b/c', 'a/b/c/d']
429
725
 
430
- See [expand-brackets](https://github.com/jonschlinkert/expand-brackets) for more information about extended bracket expressions.
726
+ mm(['a/b', 'a/b/c', 'a/b/c/d'], 'a/**', {noglobstar: true});
727
+ //=> ['a/b']
728
+ ```
431
729
 
432
- ### options.noextglob
730
+ ### options.nonull
433
731
 
434
- Don't expand extended globs.
732
+ Alias for [options.nullglob](#options-nullglob).
435
733
 
436
- Type: `{Boolean}`
734
+ ### options.nullglob
437
735
 
438
- Default: `undefined`
736
+ If `true`, when no matches are found the actual (arrayified) glob pattern is returned instead of an empty array. Same behavior as [minimatch](https://github.com/isaacs/minimatch) option `nonull`.
439
737
 
440
- See [extglob](https://github.com/jonschlinkert/extglob) for more information about extended globs.
738
+ **Type**: `Boolean`
441
739
 
442
- ### options.nocase
740
+ **Default**: `undefined`
443
741
 
444
- Use a case-insensitive regex for matching files. Same behavior as [minimatch](https://github.com/isaacs/minimatch).
742
+ ### options.snapdragon
445
743
 
446
- Type: `{Boolean}`
744
+ Pass your own instance of [snapdragon](https://github.com/jonschlinkert/snapdragon), to customize parsers or compilers.
447
745
 
448
- Default: `false`
746
+ **Type**: `Object`
449
747
 
450
- ### options.nonegate
748
+ **Default**: `undefined`
451
749
 
452
- Disallow negation (`!`) patterns.
750
+ ### options.sourcemap
453
751
 
454
- Type: `{Boolean}`
752
+ Generate a source map by enabling the `sourcemap` option with the `.parse`, `.compile`, or `.create` methods.
455
753
 
456
- Default: `false`
754
+ _(Note that sourcemaps are currently not enabled for brace patterns)_
457
755
 
458
- ### options.nonull
756
+ **Examples**
459
757
 
460
- If `true`, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty array. Same behavior as [minimatch](https://github.com/isaacs/minimatch).
758
+ ``` js
759
+ var mm = require('micromatch');
760
+ var pattern = '*(*(of*(a)x)z)';
761
+
762
+ var res = mm.create('abc/*.js', {sourcemap: true});
763
+ console.log(res.map);
764
+ // { version: 3,
765
+ // sources: [ 'string' ],
766
+ // names: [],
767
+ // mappings: 'AAAA,GAAG,EAAC,iBAAC,EAAC,EAAE',
768
+ // sourcesContent: [ 'abc/*.js' ] }
769
+
770
+ var ast = mm.parse('abc/**/*.js');
771
+ var res = mm.compile(ast, {sourcemap: true});
772
+ console.log(res.map);
773
+ // { version: 3,
774
+ // sources: [ 'string' ],
775
+ // names: [],
776
+ // mappings: 'AAAA,GAAG,EAAC,2BAAE,EAAC,iBAAC,EAAC,EAAE',
777
+ // sourcesContent: [ 'abc/**/*.js' ] }
778
+
779
+ var ast = mm.parse(pattern);
780
+ var res = mm.compile(ast, {sourcemap: true});
781
+ console.log(res.map);
782
+ // { version: 3,
783
+ // sources: [ 'string' ],
784
+ // names: [],
785
+ // mappings: 'AAAA,CAAE,CAAE,EAAE,CAAE,CAAC,EAAC,CAAC,EAAC,CAAC,EAAC',
786
+ // sourcesContent: [ '*(*(of*(a)x)z)' ] }
787
+ ```
461
788
 
462
- Type: `{Boolean}`
789
+ ### options.unescape
463
790
 
464
- Default: `false`
791
+ Remove backslashes from returned matches.
465
792
 
466
- ### options.cache
793
+ **Type**: `Boolean`
467
794
 
468
- Cache the platform (e.g. `win32`) to prevent this from being looked up for every filepath.
795
+ **Default**: `undefined`
469
796
 
470
- Type: `{Boolean}`
797
+ **Example**
471
798
 
472
- Default: `true`
799
+ In this example we want to match a literal `*`:
473
800
 
474
- ***
801
+ ```js
802
+ mm.match(['abc', 'a\\*c'], 'a\\*c');
803
+ //=> ['a\\*c']
804
+
805
+ mm.match(['abc', 'a\\*c'], 'a\\*c', {unescape: true});
806
+ //=> ['a*c']
807
+ ```
808
+
809
+ ### options.unixify
810
+
811
+ Convert path separators on returned files to posix/unix-style forward slashes.
475
812
 
476
- ## Other features
813
+ **Type**: `Boolean`
814
+
815
+ **Default**: `true` on windows, `false` everywhere else
816
+
817
+ **Example**
818
+
819
+ ```js
820
+ mm.match(['a\\b\\c'], 'a/**');
821
+ //=> ['a/b/c']
822
+
823
+ mm.match(['a\\b\\c'], {unixify: false});
824
+ //=> ['a\\b\\c']
825
+ ```
477
826
 
478
- Micromatch also supports the following.
827
+ ## Extended globbing
479
828
 
480
- ### Extended globbing
829
+ Micromatch also supports extended globbing features.
481
830
 
482
- #### extglobs
831
+ ### extglobs
483
832
 
484
833
  Extended globbing, as described by the bash man page:
485
834
 
486
835
  | **pattern** | **regex equivalent** | **description** |
487
836
  | --- | --- | --- |
488
- | `?(pattern-list)` | `(... | ...)?` | Matches zero or one occurrence of the given patterns |
489
- | `*(pattern-list)` | `(... | ...)*` | Matches zero or more occurrences of the given patterns |
490
- | `+(pattern-list)` | `(... | ...)+` | Matches one or more occurrences of the given patterns |
491
- | `@(pattern-list)` | `(... | ...)` <sup>*</sup> | Matches one of the given patterns |
492
- | `!(pattern-list)` | N/A | Matches anything except one of the given patterns |
837
+ | `?(pattern)` | `(pattern)?` | Matches zero or one occurrence of the given patterns |
838
+ | `*(pattern)` | `(pattern)*` | Matches zero or more occurrences of the given patterns |
839
+ | `+(pattern)` | `(pattern)+` | Matches one or more occurrences of the given patterns |
840
+ | `@(pattern)` | `(pattern)` <sup>*</sup> | Matches one of the given patterns |
841
+ | `!(pattern)` | N/A (equivalent regex is much more complicated) | Matches anything except one of the given patterns |
493
842
 
494
- <sup><strong>*</strong></sup> `@` isn't a RegEx character.
843
+ <sup><strong>*</strong></sup> Note that `@` isn't a RegEx character.
495
844
 
496
845
  Powered by [extglob](https://github.com/jonschlinkert/extglob). Visit that library for the full range of options or to report extglob related issues.
497
846
 
498
- See [extglob](https://github.com/jonschlinkert/extglob) for more information about extended globs.
847
+ ### braces
499
848
 
500
- #### brace expansion
849
+ Brace patterns can be used to match specific ranges or sets of characters. For example, the pattern `*/{1..3}/*` would match any of following strings:
501
850
 
502
- In simple cases, brace expansion appears to work the same way as the logical `OR` operator. For example, `(a|b)` will achieve the same result as `{a,b}`.
503
-
504
- Here are some powerful features unique to brace expansion (versus character classes):
505
-
506
- * range expansion: `a{1..3}b/*.js` expands to: `['a1b/*.js', 'a2b/*.js', 'a3b/*.js']`
507
- * nesting: `a{c,{d,e}}b/*.js` expands to: `['acb/*.js', 'adb/*.js', 'aeb/*.js']`
508
-
509
- Visit [braces](https://github.com/jonschlinkert/braces) to ask questions and create an issue related to brace-expansion, or to see the full range of features and options related to brace expansion.
851
+ ```
852
+ foo/1/bar
853
+ foo/2/bar
854
+ foo/3/bar
855
+ baz/1/qux
856
+ baz/2/qux
857
+ baz/3/qux
858
+ ```
510
859
 
511
- #### regex character classes
860
+ Visit [braces](https://github.com/micromatch/braces) to see the full range of features and options related to brace expansion, or to create brace matching or expansion related issues.
512
861
 
513
- With the exception of brace expansion (`{a,b}`, `{1..5}`, etc), most of the special characters convert directly to regex, so you can expect them to follow the same rules and produce the same results as regex.
862
+ ### regex character classes
514
863
 
515
- For example, given the list: `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:
864
+ Given the list: `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:
516
865
 
517
866
  * `[ac].js`: matches both `a` and `c`, returning `['a.js', 'c.js']`
518
867
  * `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`
@@ -521,7 +870,7 @@ For example, given the list: `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:
521
870
 
522
871
  Learn about [regex character classes](http://www.regular-expressions.info/charclass.html).
523
872
 
524
- #### regex groups
873
+ ### regex groups
525
874
 
526
875
  Given `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:
527
876
 
@@ -529,161 +878,198 @@ Given `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:
529
878
  * `(b|d).js`: would match either `b` or `d`, returning `['b.js', 'd.js']`
530
879
  * `(b|[A-Z]).js`: would match either `b` or an uppercase letter, returning `['b.js', 'E.js']`
531
880
 
532
- As with regex, parenthese can be nested, so patterns like `((a|b)|c)/b` will work. But it might be easier to achieve your goal using brace expansion.
881
+ 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.
882
+
883
+ ### POSIX bracket expressions
533
884
 
534
- #### POSIX bracket expressions
885
+ POSIX brackets are intended to be more user-friendly than regex character classes. This of course is in the eye of the beholder.
535
886
 
536
887
  **Example**
537
888
 
538
889
  ```js
539
890
  mm.isMatch('a1', '[[:alpha:][:digit:]]');
540
891
  //=> true
892
+
893
+ mm.isMatch('a1', '[[:alpha:][:alpha:]]');
894
+ //=> false
541
895
  ```
542
896
 
543
- See [expand-brackets](https://github.com/jonschlinkert/expand-brackets) for more information about extended bracket expressions.
897
+ See [expand-brackets](https://github.com/jonschlinkert/expand-brackets) for more information about bracket expressions.
544
898
 
545
899
  ***
546
900
 
547
901
  ## Notes
548
902
 
549
- Whenever possible parsing behavior for patterns is based on globbing specifications in Bash 4.3. Patterns that aren't described by Bash follow wildmatch spec (used by git).
903
+ ### Bash 4.3 parity
550
904
 
551
- ## Benchmarks
905
+ Whenever possible matching behavior is based on behavior Bash 4.3, which is mostly consistent with minimatch.
552
906
 
553
- Run the [benchmarks](./benchmark):
907
+ 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.
554
908
 
555
- ```bash
556
- node benchmark
557
- ```
909
+ ### Backslashes
558
910
 
559
- As of July 15, 2016:
911
+ There is an important, notable difference between minimatch and micromatch _in regards to how backslashes are handled_ in glob patterns.
560
912
 
561
- ```bash
562
- #1: basename-braces
563
- micromatch x 26,420 ops/sec ±0.89% (91 runs sampled)
564
- minimatch x 3,507 ops/sec ±0.64% (97 runs sampled)
913
+ * Micromatch exclusively and explicitly reserves backslashes for escaping characters in a glob pattern, even on windows. This is consistent with bash behavior.
914
+ * Minimatch converts all backslashes to forward slashes, which means you can't use backslashes to escape any characters in your glob patterns.
565
915
 
566
- #2: basename
567
- micromatch x 25,315 ops/sec ±0.82% (93 runs sampled)
568
- minimatch x 4,398 ops/sec ±0.86% (94 runs sampled)
916
+ We made this decision for micromatch for a couple of reasons:
569
917
 
570
- #3: braces-no-glob
571
- micromatch x 341,254 ops/sec ±0.78% (93 runs sampled)
572
- minimatch x 30,197 ops/sec ±1.12% (91 runs sampled)
918
+ * consistency with bash conventions.
919
+ * glob patterns are not filepaths. They are a type of [regular language](https://en.wikipedia.org/wiki/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.
573
920
 
574
- #4: braces
575
- micromatch x 54,649 ops/sec ±0.74% (94 runs sampled)
576
- minimatch x 3,095 ops/sec ±0.82% (95 runs sampled)
921
+ **A note about joining paths to globs**
577
922
 
578
- #5: immediate
579
- micromatch x 16,719 ops/sec ±0.79% (95 runs sampled)
580
- minimatch x 4,348 ops/sec ±0.86% (96 runs sampled)
923
+ 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 `\\`.
581
924
 
582
- #6: large
583
- micromatch x 721 ops/sec ±0.77% (94 runs sampled)
584
- minimatch x 17.73 ops/sec ±1.08% (50 runs sampled)
925
+ 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.
585
926
 
586
- #7: long
587
- micromatch x 5,051 ops/sec ±0.87% (97 runs sampled)
588
- minimatch x 628 ops/sec ±0.83% (94 runs sampled)
927
+ ## Contributing
589
928
 
590
- #8: mid
591
- micromatch x 51,280 ops/sec ±0.80% (95 runs sampled)
592
- minimatch x 1,923 ops/sec ±0.84% (95 runs sampled)
929
+ All contributions are welcome! Please read [the contributing guide](.github/contributing.md) to get started.
593
930
 
594
- #9: multi-patterns
595
- micromatch x 22,440 ops/sec ±0.97% (94 runs sampled)
596
- minimatch x 2,481 ops/sec ±1.10% (94 runs sampled)
931
+ **Bug reports**
597
932
 
598
- #10: no-glob
599
- micromatch x 722,823 ops/sec ±1.30% (87 runs sampled)
600
- minimatch x 52,967 ops/sec ±1.09% (94 runs sampled)
933
+ 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:
601
934
 
602
- #11: range
603
- micromatch x 243,471 ops/sec ±0.79% (94 runs sampled)
604
- minimatch x 11,736 ops/sec ±0.82% (96 runs sampled)
935
+ * [research existing issues first](../../issues) (open and closed)
936
+ * visit the [GNU Bash documentation](https://www.gnu.org/software/bash/manual/) to see how Bash deals with the pattern
937
+ * visit the [minimatch](https://github.com/isaacs/minimatch) documentation to cross-check expected behavior in node.js
938
+ * 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.
605
939
 
606
- #12: shallow
607
- micromatch x 190,874 ops/sec ±0.98% (95 runs sampled)
608
- minimatch x 21,699 ops/sec ±0.81% (97 runs sampled)
940
+ **Platform issues**
609
941
 
610
- #13: short
611
- micromatch x 496,393 ops/sec ±3.86% (90 runs sampled)
612
- minimatch x 53,765 ops/sec ±0.75% (95 runs sampled)
613
- ```
942
+ 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).
614
943
 
615
- ## Tests
944
+ ## Benchmarks
616
945
 
617
- ### Running tests
946
+ ### Running benchmarks
618
947
 
619
948
  Install dev dependencies:
620
949
 
621
- ```sh
622
- $ npm install -d && npm test
950
+ ```bash
951
+ npm i -d && npm run benchmark
623
952
  ```
624
953
 
625
- ### Coverage
954
+ ### Latest results
626
955
 
627
- As of July 15, 2016:
956
+ As of June 02, 2017 (longer bars are better):
628
957
 
629
958
  ```sh
630
- Statements : 100% (441/441)
631
- Branches : 100% (270/270)
632
- Functions : 100% (54/54)
633
- Lines : 100% (429/429)
634
- ```
959
+ # braces-globstar-large-list
960
+ micromatch ██████████████████████████████████████████████████ (595 ops/sec)
961
+ minimatch (13.95 ops/sec)
962
+ multimatch (14.09 ops/sec)
963
+
964
+ # braces-multiple
965
+ micromatch ██████████████████████████████████████████████████ (48,362 ops/sec)
966
+ minimatch (2.18 ops/sec)
967
+ multimatch (2.15 ops/sec)
968
+
969
+ # braces-range
970
+ micromatch ██████████████████████████████████████████████████ (187,481 ops/sec)
971
+ minimatch ███ (12,366 ops/sec)
972
+ multimatch ███ (11,841 ops/sec)
973
+
974
+ # braces-set
975
+ micromatch ██████████████████████████████████████████████████ (24,344 ops/sec)
976
+ minimatch ████ (2,255 ops/sec)
977
+ multimatch ████ (2,199 ops/sec)
978
+
979
+ # globstar-large-list
980
+ micromatch ██████████████████████████████████████████████████ (561 ops/sec)
981
+ minimatch ██ (25.43 ops/sec)
982
+ multimatch ██ (25.27 ops/sec)
983
+
984
+ # globstar-long-list
985
+ micromatch ██████████████████████████████████████████████████ (3,257 ops/sec)
986
+ minimatch ███████ (485 ops/sec)
987
+ multimatch ███████ (485 ops/sec)
988
+
989
+ # globstar-short-list
990
+ micromatch ██████████████████████████████████████████████████ (359,991 ops/sec)
991
+ minimatch ██████ (44,763 ops/sec)
992
+ multimatch █████ (39,977 ops/sec)
993
+
994
+ # no-glob
995
+ micromatch ██████████████████████████████████████████████████ (443,740 ops/sec)
996
+ minimatch ████ (44,152 ops/sec)
997
+ multimatch ████ (41,077 ops/sec)
998
+
999
+ # star-basename
1000
+ micromatch ██████████████████████████████████████████████████ (10,286 ops/sec)
1001
+ minimatch ██████████████ (3,059 ops/sec)
1002
+ multimatch ███████████████ (3,129 ops/sec)
1003
+
1004
+ # star
1005
+ micromatch ██████████████████████████████████████████████████ (9,756 ops/sec)
1006
+ minimatch ███████████████ (2,978 ops/sec)
1007
+ multimatch ███████████████ (2,970 ops/sec)
635
1008
 
636
- ## Contributing
637
-
638
- Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
1009
+ ```
639
1010
 
640
- Please be sure to run the benchmarks before/after any code changes to judge the impact before you do a PR. thanks!
1011
+ ## About
641
1012
 
642
- ## Related
1013
+ ### Related projects
643
1014
 
644
- * [braces](https://www.npmjs.com/package/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces) | [homepage](https://github.com/jonschlinkert/braces "Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces specification.")
1015
+ * [braces](https://www.npmjs.com/package/braces): Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… [more](https://github.com/micromatch/braces) | [homepage](https://github.com/micromatch/braces "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.")
645
1016
  * [expand-brackets](https://www.npmjs.com/package/expand-brackets): Expand POSIX bracket expressions (character classes) in glob patterns. | [homepage](https://github.com/jonschlinkert/expand-brackets "Expand POSIX bracket expressions (character classes) in glob patterns.")
646
- * [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… [more](https://github.com/jonschlinkert/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks. Used by micromatch.")
647
- * [extglob](https://www.npmjs.com/package/extglob): Convert extended globs to regex-compatible strings. Add (almost) the expressive power of regular expressions to… [more](https://github.com/jonschlinkert/extglob) | [homepage](https://github.com/jonschlinkert/extglob "Convert extended globs to regex-compatible strings. Add (almost) the expressive power of regular expressions to glob patterns.")
648
- * [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or multiplier to use.")
649
- * [gulp-micromatch](https://www.npmjs.com/package/gulp-micromatch): Filter vinyl files with glob patterns, string, regexp, array, object or matcher function. micromatch stream. | [homepage](https://github.com/tunnckocore/gulp-micromatch#readme "Filter vinyl files with glob patterns, string, regexp, array, object or matcher function. micromatch stream.")
650
- * [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern… [more](https://github.com/jonschlinkert/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob "Returns `true` if the given string looks like a glob pattern or an extglob pattern. This makes it easy to create code that only uses external modules like node-glob when necessary, resulting in much faster code execution and initialization time, and a bet")
651
- * [parse-glob](https://www.npmjs.com/package/parse-glob): Parse a glob pattern into an object of tokens. | [homepage](https://github.com/jonschlinkert/parse-glob "Parse a glob pattern into an object of tokens.")
1017
+ * [extglob](https://www.npmjs.com/package/extglob): Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… [more](https://github.com/jonschlinkert/extglob) | [homepage](https://github.com/jonschlinkert/extglob "Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.")
1018
+ * [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`")
1019
+ * [nanomatch](https://www.npmjs.com/package/nanomatch): Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash… [more](https://github.com/jonschlinkert/nanomatch) | [homepage](https://github.com/jonschlinkert/nanomatch "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)")
652
1020
 
653
- ## Contributing
1021
+ ### Contributing
654
1022
 
655
1023
  Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
656
1024
 
657
- ## Building docs
1025
+ Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
1026
+
1027
+ ### Contributors
1028
+
1029
+ | **Commits** | **Contributor** |
1030
+ | --- | --- |
1031
+ | 423 | [jonschlinkert](https://github.com/jonschlinkert) |
1032
+ | 12 | [es128](https://github.com/es128) |
1033
+ | 3 | [paulmillr](https://github.com/paulmillr) |
1034
+ | 2 | [TrySound](https://github.com/TrySound) |
1035
+ | 2 | [doowb](https://github.com/doowb) |
1036
+ | 2 | [MartinKolarik](https://github.com/MartinKolarik) |
1037
+ | 2 | [tunnckoCore](https://github.com/tunnckoCore) |
1038
+ | 1 | [amilajack](https://github.com/amilajack) |
1039
+ | 1 | [DianeLooney](https://github.com/DianeLooney) |
1040
+ | 1 | [UltCombo](https://github.com/UltCombo) |
1041
+ | 1 | [tomByrer](https://github.com/tomByrer) |
658
1042
 
659
- _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
1043
+ ### Building docs
660
1044
 
661
- To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
1045
+ _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
1046
+
1047
+ To generate the readme, run the following command:
662
1048
 
663
1049
  ```sh
664
- $ npm install -g verb verb-generate-readme && verb
1050
+ $ npm install -g verbose/verb#dev verb-generate-readme && verb
665
1051
  ```
666
1052
 
667
- ## Running tests
1053
+ ### Running tests
668
1054
 
669
- Install dev dependencies:
1055
+ Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
670
1056
 
671
1057
  ```sh
672
- $ npm install -d && npm test
1058
+ $ npm install && npm test
673
1059
  ```
674
1060
 
675
- ## Author
1061
+ ### Author
676
1062
 
677
1063
  **Jon Schlinkert**
678
1064
 
679
1065
  * [github/jonschlinkert](https://github.com/jonschlinkert)
680
- * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
1066
+ * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
681
1067
 
682
- ## License
1068
+ ### License
683
1069
 
684
- Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
685
- Released under the [MIT license](https://github.com/jonschlinkert/micromatch/blob/master/LICENSE).
1070
+ Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
1071
+ Released under the [MIT License](LICENSE).
686
1072
 
687
1073
  ***
688
1074
 
689
- _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 15, 2016._
1075
+ _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 02, 2017._