micromatch
Advanced tools
Comparing version
38
index.js
@@ -518,2 +518,40 @@ 'use strict'; | ||
/** | ||
* Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match. | ||
* | ||
* ```js | ||
* var mm = require('micromatch'); | ||
* mm.capture(pattern, string[, options]); | ||
* | ||
* console.log(mm.capture('test/*.js', 'test/foo.js)); | ||
* //=> ['foo'] | ||
* console.log(mm.capture('test/*.js', 'foo/bar.css')); | ||
* //=> null | ||
* ``` | ||
* @param {String} `pattern` Glob pattern to use for matching. | ||
* @param {String} `string` String to match | ||
* @param {Object} `options` See available [options](#options) for changing how matches are performed | ||
* @return {Boolean} Returns an array of captures if the string matches the glob pattern, otherwise `null`. | ||
* @api public | ||
*/ | ||
micromatch.capture = function(pattern, str, options) { | ||
var re = micromatch.makeRe(pattern, extend({capture: true}, options)); | ||
var unixify = utils.unixify(options); | ||
function match() { | ||
return function(string) { | ||
var match = re.exec(unixify(string)); | ||
if (!match) { | ||
return null; | ||
} | ||
return match.slice(1); | ||
}; | ||
} | ||
var capture = memoize('capture', pattern, options, match); | ||
return capture(str); | ||
}; | ||
/** | ||
* Create a regular expression from the given glob `pattern`. | ||
@@ -520,0 +558,0 @@ * |
{ | ||
"name": "micromatch", | ||
"description": "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.", | ||
"version": "3.0.5", | ||
"version": "3.1.0", | ||
"homepage": "https://github.com/micromatch/micromatch", | ||
@@ -43,3 +43,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"extend-shallow": "^2.0.1", | ||
"extglob": "^2.0.0", | ||
"extglob": "^2.0.2", | ||
"fragment-cache": "^0.2.1", | ||
@@ -46,0 +46,0 @@ "kind-of": "^5.0.2", |
154
README.md
@@ -401,4 +401,27 @@ # 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) | ||
### [.makeRe](index.js#L533) | ||
### [.capture](index.js#L536) | ||
Returns an array of matches captured by `pattern` in `string, or`null` if the pattern did not match. | ||
**Params** | ||
* `pattern` **{String}**: Glob pattern to use for matching. | ||
* `string` **{String}**: String to match | ||
* `options` **{Object}**: See available [options](#options) for changing how matches are performed | ||
* `returns` **{Boolean}**: Returns an array of captures if the string matches the glob pattern, otherwise `null`. | ||
**Example** | ||
```js | ||
var mm = require('micromatch'); | ||
mm.capture(pattern, string[, options]); | ||
console.log(mm.capture('test/*.js', 'test/foo.js)); | ||
//=> ['foo'] | ||
console.log(mm.capture('test/*.js', 'foo/bar.css')); | ||
//=> null | ||
``` | ||
### [.makeRe](index.js#L571) | ||
Create a regular expression from the given glob `pattern`. | ||
@@ -422,3 +445,3 @@ | ||
### [.braces](index.js#L580) | ||
### [.braces](index.js#L618) | ||
@@ -444,3 +467,3 @@ Expand the given brace `pattern`. | ||
### [.create](index.js#L647) | ||
### [.create](index.js#L685) | ||
@@ -487,3 +510,3 @@ 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. | ||
### [.parse](index.js#L694) | ||
### [.parse](index.js#L732) | ||
@@ -521,3 +544,3 @@ Parse the given `str` with the given `options`. | ||
### [.compile](index.js#L747) | ||
### [.compile](index.js#L785) | ||
@@ -556,3 +579,3 @@ Compile the given `ast` or string with the given `options`. | ||
### [.clearCache](index.js#L768) | ||
### [.clearCache](index.js#L806) | ||
@@ -966,55 +989,88 @@ Clear the regex cache. | ||
As of September 07, 2017 (longer bars are better): | ||
As of September 11, 2017 (longer bars are better): | ||
```sh | ||
# braces-globstar-large-list | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (595 ops/sec) | ||
minimatch β (13.95 ops/sec) | ||
multimatch β (14.09 ops/sec) | ||
# braces-globstar-large-list (485691 bytes) | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (517 ops/sec Β±0.49%) | ||
minimatch β (18.92 ops/sec Β±0.54%) | ||
multimatch β (18.94 ops/sec Β±0.62%) | ||
# braces-multiple | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (48,362 ops/sec) | ||
minimatch (2.18 ops/sec) | ||
multimatch (2.15 ops/sec) | ||
micromatch is faster by an avg. of 2,733% | ||
# braces-range | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (187,481 ops/sec) | ||
minimatch βββ (12,366 ops/sec) | ||
multimatch βββ (11,841 ops/sec) | ||
# braces-multiple (3362 bytes) | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (33,625 ops/sec Β±0.45%) | ||
minimatch (2.92 ops/sec Β±3.26%) | ||
multimatch (2.90 ops/sec Β±2.76%) | ||
# braces-set | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (24,344 ops/sec) | ||
minimatch ββββ (2,255 ops/sec) | ||
multimatch ββββ (2,199 ops/sec) | ||
micromatch is faster by an avg. of 1,156,935% | ||
# globstar-large-list | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (561 ops/sec) | ||
minimatch ββ (25.43 ops/sec) | ||
multimatch ββ (25.27 ops/sec) | ||
# braces-range (727 bytes) | ||
micromatch βββββββββββββββββββββββββββββββββββββββββββββββββ (155,220 ops/sec Β±0.56%) | ||
minimatch ββββββ (20,186 ops/sec Β±1.27%) | ||
multimatch ββββββ (19,809 ops/sec Β±0.60%) | ||
# globstar-long-list | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (3,257 ops/sec) | ||
minimatch βββββββ (485 ops/sec) | ||
multimatch βββββββ (485 ops/sec) | ||
micromatch is faster by an avg. of 776% | ||
# globstar-short-list | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (359,991 ops/sec) | ||
minimatch ββββββ (44,763 ops/sec) | ||
multimatch βββββ (39,977 ops/sec) | ||
# braces-set (2858 bytes) | ||
micromatch βββββββββββββββββββββββββββββββββββββββββββββββββ (24,354 ops/sec Β±0.92%) | ||
minimatch βββββ (2,566 ops/sec Β±0.56%) | ||
multimatch ββββ (2,431 ops/sec Β±1.25%) | ||
# no-glob | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (443,740 ops/sec) | ||
minimatch ββββ (44,152 ops/sec) | ||
multimatch ββββ (41,077 ops/sec) | ||
micromatch is faster by an avg. of 975% | ||
# star-basename | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (10,286 ops/sec) | ||
minimatch ββββββββββββββ (3,059 ops/sec) | ||
multimatch βββββββββββββββ (3,129 ops/sec) | ||
# globstar-large-list (485686 bytes) | ||
micromatch βββββββββββββββββββββββββββββββββββββββββββββββββ (504 ops/sec Β±0.45%) | ||
minimatch βββ (33.36 ops/sec Β±1.08%) | ||
multimatch βββ (33.19 ops/sec Β±1.35%) | ||
# star | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (9,756 ops/sec) | ||
minimatch βββββββββββββββ (2,978 ops/sec) | ||
multimatch βββββββββββββββ (2,970 ops/sec) | ||
micromatch is faster by an avg. of 1,514% | ||
# globstar-long-list (90647 bytes) | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (2,694 ops/sec Β±1.08%) | ||
minimatch ββββββββββββββββ (870 ops/sec Β±1.09%) | ||
multimatch ββββββββββββββββ (862 ops/sec Β±0.84%) | ||
micromatch is faster by an avg. of 311% | ||
# globstar-short-list (182 bytes) | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (328,921 ops/sec Β±1.06%) | ||
minimatch βββββββββ (64,808 ops/sec Β±1.42%) | ||
multimatch ββββββββ (57,991 ops/sec Β±2.11%) | ||
micromatch is faster by an avg. of 536% | ||
# no-glob (701 bytes) | ||
micromatch βββββββββββββββββββββββββββββββββββββββββββββββββ (415,935 ops/sec Β±0.36%) | ||
minimatch βββββββββββ (92,730 ops/sec Β±1.44%) | ||
multimatch βββββββββ (81,958 ops/sec Β±2.13%) | ||
micromatch is faster by an avg. of 476% | ||
# star-basename-long (12339 bytes) | ||
micromatch βββββββββββββββββββββββββββββββββββββββββββββββββ (7,963 ops/sec Β±0.36%) | ||
minimatch βββββββββββββββββββββββββββββββ (5,072 ops/sec Β±0.83%) | ||
multimatch βββββββββββββββββββββββββββββββ (5,028 ops/sec Β±0.40%) | ||
micromatch is faster by an avg. of 158% | ||
# star-basename-short (349 bytes) | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (269,552 ops/sec Β±0.70%) | ||
minimatch ββββββββββββββββββββββ (122,457 ops/sec Β±1.39%) | ||
multimatch ββββββββββββββββββββ (110,788 ops/sec Β±1.99%) | ||
micromatch is faster by an avg. of 231% | ||
# star-folder-long (19207 bytes) | ||
micromatch βββββββββββββββββββββββββββββββββββββββββββββββββ (3,806 ops/sec Β±0.38%) | ||
minimatch ββββββββββββββββββββββββββββ (2,204 ops/sec Β±0.32%) | ||
multimatch ββββββββββββββββββββββββββ (2,020 ops/sec Β±1.07%) | ||
micromatch is faster by an avg. of 180% | ||
# star-folder-short (551 bytes) | ||
micromatch ββββββββββββββββββββββββββββββββββββββββββββββββββ (249,077 ops/sec Β±0.40%) | ||
minimatch βββββββββββ (59,431 ops/sec Β±1.67%) | ||
multimatch βββββββββββ (55,569 ops/sec Β±1.43%) | ||
micromatch is faster by an avg. of 433% | ||
``` | ||
@@ -1044,3 +1100,3 @@ | ||
| --- | --- | | ||
| 430 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 439 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 12 | [es128](https://github.com/es128) | | ||
@@ -1090,2 +1146,2 @@ | 8 | [doowb](https://github.com/doowb) | | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 07, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 11, 2017._ |
84683
4.76%1169
2.9%1138
5.18%Updated