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/CHANGELOG.md +37 -0
- package/LICENSE +1 -1
- package/README.md +735 -349
- package/index.js +699 -283
- package/lib/cache.js +1 -0
- package/lib/compilers.js +78 -0
- package/lib/parsers.js +83 -0
- package/lib/utils.js +246 -83
- package/package.json +85 -47
- package/lib/chars.js +0 -67
- package/lib/expand.js +0 -304
- package/lib/glob.js +0 -193
package/README.md
CHANGED
@@ -1,12 +1,54 @@
|
|
1
|
-
# micromatch [](https://www.npmjs.com/package/micromatch) [](https://npmjs.org/package/micromatch) [](https://www.npmjs.com/package/micromatch) [](https://npmjs.org/package/micromatch) [](https://npmjs.org/package/micromatch) [](https://travis-ci.org/micromatch/micromatch) [](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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
##
|
61
|
+
## Quickstart
|
20
62
|
|
21
63
|
```js
|
22
64
|
var mm = require('micromatch');
|
23
|
-
|
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
|
-
|
70
|
+
```js
|
71
|
+
console.log(mm(['foo', 'bar', 'qux'], ['f*', 'b*']));
|
72
|
+
//=> ['foo', 'bar']
|
73
|
+
```
|
29
74
|
|
30
|
-
|
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
|
-
|
77
|
+
```js
|
78
|
+
console.log(mm.isMatch('foo', 'f*'));
|
79
|
+
//=> true
|
80
|
+
```
|
37
81
|
|
38
|
-
|
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
|
-
|
84
|
+
## Why use micromatch?
|
44
85
|
|
45
|
-
|
86
|
+
> micromatch is a [drop-in replacement](#switching-to-micromatch) for minimatch and multimatch
|
46
87
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
107
|
+
You can mix and match these features to create whatever patterns you need!
|
54
108
|
|
55
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
###
|
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
|
-
|
140
|
+
### [micromatch](index.js#L41)
|
89
141
|
|
90
|
-
|
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
|
-
|
161
|
+
### [.match](index.js#L95)
|
97
162
|
|
98
|
-
|
99
|
-
|
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
|
106
|
-
|
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
|
-
###
|
182
|
+
### [.isMatch](index.js#L156)
|
183
|
+
|
184
|
+
Returns true if the specified `string` matches the given glob `pattern`.
|
185
|
+
|
186
|
+
**Params**
|
110
187
|
|
111
|
-
**
|
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
|
-
|
193
|
+
**Example**
|
114
194
|
|
115
195
|
```js
|
116
|
-
mm
|
117
|
-
|
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
|
-
|
205
|
+
### [.some](index.js#L194)
|
121
206
|
|
122
|
-
|
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
|
219
|
+
var mm = require('micromatch');
|
220
|
+
mm.some(list, patterns[, options]);
|
126
221
|
|
127
|
-
|
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
|
-
|
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
|
-
|
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
|
136
|
-
|
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
|
-
|
255
|
+
### [.any](index.js#L262)
|
140
256
|
|
141
|
-
|
257
|
+
Returns true if **any** of the given glob `patterns` match the specified `string`.
|
142
258
|
|
143
|
-
|
144
|
-
|
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
|
148
|
-
|
269
|
+
var mm = require('micromatch');
|
270
|
+
mm.any(string, patterns[, options]);
|
149
271
|
|
150
|
-
mm(
|
151
|
-
//=>
|
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
|
-
|
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
|
-
|
295
|
+
console.log(mm.all('foo.js', ['foo.js']));
|
296
|
+
// true
|
163
297
|
|
164
|
-
|
165
|
-
|
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
|
-
|
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
|
174
|
-
|
322
|
+
var mm = require('micromatch');
|
323
|
+
mm.not(list, patterns[, options]);
|
175
324
|
|
176
|
-
mm.
|
177
|
-
//=> ['
|
325
|
+
console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
|
326
|
+
//=> ['b.b', 'c.c']
|
178
327
|
```
|
179
328
|
|
180
|
-
### .
|
329
|
+
### [.contains](index.js#L377)
|
181
330
|
|
182
|
-
|
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
|
-
|
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
|
192
|
-
|
343
|
+
var mm = require('micromatch');
|
344
|
+
mm.contains(string, pattern[, options]);
|
193
345
|
|
194
|
-
mm.
|
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
|
-
### .
|
352
|
+
### [.matchKeys](index.js#L433)
|
199
353
|
|
200
|
-
|
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
|
-
**
|
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
|
-
|
363
|
+
**Example**
|
205
364
|
|
206
365
|
```js
|
207
|
-
mm
|
208
|
-
|
366
|
+
var mm = require('micromatch');
|
367
|
+
mm.matchKeys(object, patterns[, options]);
|
209
368
|
|
210
|
-
|
211
|
-
|
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
|
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
|
-
**
|
219
|
-
|
220
|
-
Can be any of the following:
|
378
|
+
**Params**
|
221
379
|
|
222
|
-
* `
|
223
|
-
* `
|
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
|
230
|
-
|
387
|
+
var mm = require('micromatch');
|
388
|
+
mm.matcher(pattern[, options]);
|
231
389
|
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
-
### .
|
397
|
+
### [.makeRe](index.js#L534)
|
240
398
|
|
241
|
-
|
399
|
+
Create a regular expression from the given glob `pattern`.
|
242
400
|
|
243
401
|
**Params**
|
244
402
|
|
245
|
-
* `
|
246
|
-
|
247
|
-
**
|
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
|
-
|
407
|
+
**Example**
|
250
408
|
|
251
409
|
```js
|
252
|
-
var
|
253
|
-
[
|
254
|
-
//=> ['c.md']
|
410
|
+
var mm = require('micromatch');
|
411
|
+
mm.makeRe(pattern[, options]);
|
255
412
|
|
256
|
-
|
257
|
-
[
|
258
|
-
//=> ['a', 'b', 'c']
|
413
|
+
console.log(mm.makeRe('*.js'));
|
414
|
+
//=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
|
259
415
|
```
|
260
416
|
|
261
|
-
|
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
|
430
|
+
var mm = require('micromatch');
|
431
|
+
console.log(mm.braces('foo/{a,b}/bar'));
|
432
|
+
//=> ['foo/(a|b)/bar']
|
265
433
|
|
266
|
-
|
267
|
-
|
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
|
-
|
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
|
-
|
442
|
+
**Params**
|
274
443
|
|
275
|
-
|
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
|
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
|
-
*
|
284
|
-
*
|
285
|
-
*
|
486
|
+
* `str` **{String}**
|
487
|
+
* `options` **{Object}**
|
488
|
+
* `returns` **{Object}**: Returns an AST
|
286
489
|
|
287
490
|
**Example**
|
288
491
|
|
289
492
|
```js
|
290
|
-
mm
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
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
|
-
### .
|
513
|
+
### [.compile](index.js#L748)
|
301
514
|
|
302
|
-
|
515
|
+
Compile the given `ast` or string with the given `options`.
|
303
516
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
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
|
338
|
-
|
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
|
-
|
547
|
+
### [.clearCache](index.js#L769)
|
342
548
|
|
343
|
-
|
549
|
+
Clear the regex cache.
|
344
550
|
|
345
|
-
|
551
|
+
**Example**
|
346
552
|
|
347
|
-
|
553
|
+
```js
|
554
|
+
mm.clearCache();
|
555
|
+
```
|
348
556
|
|
349
|
-
|
557
|
+
## Options
|
350
558
|
|
351
|
-
|
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
|
-
|
586
|
+
**Example**
|
354
587
|
|
355
|
-
|
588
|
+
```js
|
589
|
+
mm(['a/b.js', 'a/c.md'], '*.js');
|
590
|
+
//=> []
|
356
591
|
|
357
|
-
|
592
|
+
mm(['a/b.js', 'a/c.md'], '*.js', {matchBase: true});
|
593
|
+
//=> ['a/b.js']
|
594
|
+
```
|
358
595
|
|
359
|
-
### options.
|
596
|
+
### options.bash
|
360
597
|
|
361
|
-
|
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
|
600
|
+
**Type**: `Boolean`
|
364
601
|
|
365
|
-
Default
|
602
|
+
**Default**: `true`
|
366
603
|
|
367
604
|
**Example**
|
368
605
|
|
369
606
|
```js
|
370
|
-
|
371
|
-
|
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
|
672
|
+
**Type**: `Boolean`
|
379
673
|
|
380
|
-
Default
|
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(['
|
388
|
-
//=> ['
|
681
|
+
mm.match(['a/b/c', 'a/b/c'], 'a/b/c');
|
682
|
+
//=> ['a/b/c', 'a/b/c']
|
389
683
|
|
390
|
-
mm.match(['
|
684
|
+
mm.match(['a/b/c', 'a/b/c'], 'a/b/c', {nodupes: true});
|
391
685
|
//=> ['abc']
|
392
686
|
```
|
393
687
|
|
394
|
-
### options.
|
688
|
+
### options.noext
|
395
689
|
|
396
|
-
|
690
|
+
Disable extglob support, so that extglobs are regarded as literal characters.
|
397
691
|
|
398
|
-
Type
|
692
|
+
**Type**: `Boolean`
|
399
693
|
|
400
|
-
Default
|
694
|
+
**Default**: `undefined`
|
401
695
|
|
402
|
-
**
|
696
|
+
**Examples**
|
403
697
|
|
404
698
|
```js
|
405
|
-
mm(['a/
|
406
|
-
//=> []
|
699
|
+
mm(['a/z', 'a/b', 'a/!(z)'], 'a/!(z)');
|
700
|
+
//=> ['a/b', 'a/!(z)']
|
407
701
|
|
408
|
-
mm(['a/
|
409
|
-
//=> ['a
|
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.
|
706
|
+
### options.nonegate
|
413
707
|
|
414
|
-
|
708
|
+
Disallow negation (`!`) patterns, and treat leading `!` as a literal character to match.
|
415
709
|
|
416
|
-
Type
|
710
|
+
**Type**: `Boolean`
|
417
711
|
|
418
|
-
Default
|
712
|
+
**Default**: `undefined`
|
419
713
|
|
420
|
-
|
714
|
+
### options.noglobstar
|
421
715
|
|
422
|
-
|
716
|
+
Disable matching with globstars (`**`).
|
423
717
|
|
424
|
-
|
718
|
+
**Type**: `Boolean`
|
425
719
|
|
426
|
-
|
720
|
+
**Default**: `undefined`
|
427
721
|
|
428
|
-
|
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
|
-
|
726
|
+
mm(['a/b', 'a/b/c', 'a/b/c/d'], 'a/**', {noglobstar: true});
|
727
|
+
//=> ['a/b']
|
728
|
+
```
|
431
729
|
|
432
|
-
### options.
|
730
|
+
### options.nonull
|
433
731
|
|
434
|
-
|
732
|
+
Alias for [options.nullglob](#options-nullglob).
|
435
733
|
|
436
|
-
|
734
|
+
### options.nullglob
|
437
735
|
|
438
|
-
|
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
|
-
|
738
|
+
**Type**: `Boolean`
|
441
739
|
|
442
|
-
|
740
|
+
**Default**: `undefined`
|
443
741
|
|
444
|
-
|
742
|
+
### options.snapdragon
|
445
743
|
|
446
|
-
|
744
|
+
Pass your own instance of [snapdragon](https://github.com/jonschlinkert/snapdragon), to customize parsers or compilers.
|
447
745
|
|
448
|
-
|
746
|
+
**Type**: `Object`
|
449
747
|
|
450
|
-
|
748
|
+
**Default**: `undefined`
|
451
749
|
|
452
|
-
|
750
|
+
### options.sourcemap
|
453
751
|
|
454
|
-
|
752
|
+
Generate a source map by enabling the `sourcemap` option with the `.parse`, `.compile`, or `.create` methods.
|
455
753
|
|
456
|
-
|
754
|
+
_(Note that sourcemaps are currently not enabled for brace patterns)_
|
457
755
|
|
458
|
-
|
756
|
+
**Examples**
|
459
757
|
|
460
|
-
|
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
|
-
|
789
|
+
### options.unescape
|
463
790
|
|
464
|
-
|
791
|
+
Remove backslashes from returned matches.
|
465
792
|
|
466
|
-
|
793
|
+
**Type**: `Boolean`
|
467
794
|
|
468
|
-
|
795
|
+
**Default**: `undefined`
|
469
796
|
|
470
|
-
|
797
|
+
**Example**
|
471
798
|
|
472
|
-
|
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
|
-
|
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
|
-
|
827
|
+
## Extended globbing
|
479
828
|
|
480
|
-
|
829
|
+
Micromatch also supports extended globbing features.
|
481
830
|
|
482
|
-
|
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
|
489
|
-
| `*(pattern
|
490
|
-
| `+(pattern
|
491
|
-
| `@(pattern
|
492
|
-
| `!(pattern
|
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
|
-
|
847
|
+
### braces
|
499
848
|
|
500
|
-
|
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
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
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
|
-
|
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
|
-
|
862
|
+
### regex character classes
|
514
863
|
|
515
|
-
|
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
|
-
|
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,
|
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
|
-
|
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
|
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
|
-
|
903
|
+
### Bash 4.3 parity
|
550
904
|
|
551
|
-
|
905
|
+
Whenever possible matching behavior is based on behavior Bash 4.3, which is mostly consistent with minimatch.
|
552
906
|
|
553
|
-
|
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
|
-
|
556
|
-
node benchmark
|
557
|
-
```
|
909
|
+
### Backslashes
|
558
910
|
|
559
|
-
|
911
|
+
There is an important, notable difference between minimatch and micromatch _in regards to how backslashes are handled_ in glob patterns.
|
560
912
|
|
561
|
-
|
562
|
-
|
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
|
-
|
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
|
-
|
571
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
603
|
-
|
604
|
-
|
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
|
-
|
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
|
-
|
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
|
-
##
|
944
|
+
## Benchmarks
|
616
945
|
|
617
|
-
### Running
|
946
|
+
### Running benchmarks
|
618
947
|
|
619
948
|
Install dev dependencies:
|
620
949
|
|
621
|
-
```
|
622
|
-
|
950
|
+
```bash
|
951
|
+
npm i -d && npm run benchmark
|
623
952
|
```
|
624
953
|
|
625
|
-
###
|
954
|
+
### Latest results
|
626
955
|
|
627
|
-
As of
|
956
|
+
As of June 02, 2017 (longer bars are better):
|
628
957
|
|
629
958
|
```sh
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
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
|
-
|
637
|
-
|
638
|
-
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
1009
|
+
```
|
639
1010
|
|
640
|
-
|
1011
|
+
## About
|
641
1012
|
|
642
|
-
|
1013
|
+
### Related projects
|
643
1014
|
|
644
|
-
* [braces](https://www.npmjs.com/package/braces):
|
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
|
-
* [
|
647
|
-
* [
|
648
|
-
* [
|
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
|
-
|
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
|
-
|
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
|
-
|
1043
|
+
### Building docs
|
660
1044
|
|
661
|
-
|
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
|
-
|
1053
|
+
### Running tests
|
668
1054
|
|
669
|
-
|
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
|
1058
|
+
$ npm install && npm test
|
673
1059
|
```
|
674
1060
|
|
675
|
-
|
1061
|
+
### Author
|
676
1062
|
|
677
1063
|
**Jon Schlinkert**
|
678
1064
|
|
679
1065
|
* [github/jonschlinkert](https://github.com/jonschlinkert)
|
680
|
-
* [twitter/jonschlinkert](
|
1066
|
+
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
|
681
1067
|
|
682
|
-
|
1068
|
+
### License
|
683
1069
|
|
684
|
-
Copyright ©
|
685
|
-
Released under the [MIT
|
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.
|
1075
|
+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 02, 2017._
|