micromatch 3.0.5 → 3.1.0

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.

Files changed (3) hide show
  1. package/README.md +114 -58
  2. package/index.js +38 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -398,7 +398,30 @@ console.log(isMatch('a.b'));
398
398
  //=> true
399
399
  ```
400
400
 
401
- ### [.makeRe](index.js#L533)
401
+ ### [.capture](index.js#L536)
402
+
403
+ Returns an array of matches captured by `pattern` in `string, or`null` if the pattern did not match.
404
+
405
+ **Params**
406
+
407
+ * `pattern` **{String}**: Glob pattern to use for matching.
408
+ * `string` **{String}**: String to match
409
+ * `options` **{Object}**: See available [options](#options) for changing how matches are performed
410
+ * `returns` **{Boolean}**: Returns an array of captures if the string matches the glob pattern, otherwise `null`.
411
+
412
+ **Example**
413
+
414
+ ```js
415
+ var mm = require('micromatch');
416
+ mm.capture(pattern, string[, options]);
417
+
418
+ console.log(mm.capture('test/*.js', 'test/foo.js));
419
+ //=> ['foo']
420
+ console.log(mm.capture('test/*.js', 'foo/bar.css'));
421
+ //=> null
422
+ ```
423
+
424
+ ### [.makeRe](index.js#L571)
402
425
 
403
426
  Create a regular expression from the given glob `pattern`.
404
427
 
@@ -418,7 +441,7 @@ console.log(mm.makeRe('*.js'));
418
441
  //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
419
442
  ```
420
443
 
421
- ### [.braces](index.js#L580)
444
+ ### [.braces](index.js#L618)
422
445
 
423
446
  Expand the given brace `pattern`.
424
447
 
@@ -439,7 +462,7 @@ console.log(mm.braces('foo/{a,b}/bar', {expand: true}));
439
462
  //=> ['foo/(a|b)/bar']
440
463
  ```
441
464
 
442
- ### [.create](index.js#L647)
465
+ ### [.create](index.js#L685)
443
466
 
444
467
  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.
445
468
 
@@ -481,7 +504,7 @@ console.log(mm.create('abc/*.js'));
481
504
  // idx: 6 }]
482
505
  ```
483
506
 
484
- ### [.parse](index.js#L694)
507
+ ### [.parse](index.js#L732)
485
508
 
486
509
  Parse the given `str` with the given `options`.
487
510
 
@@ -514,7 +537,7 @@ console.log(ast);
514
537
  // { type: 'eos', val: '' } ] }
515
538
  ```
516
539
 
517
- ### [.compile](index.js#L747)
540
+ ### [.compile](index.js#L785)
518
541
 
519
542
  Compile the given `ast` or string with the given `options`.
520
543
 
@@ -548,7 +571,7 @@ console.log(mm.compile(ast));
548
571
  // parsingErrors: [] }
549
572
  ```
550
573
 
551
- ### [.clearCache](index.js#L768)
574
+ ### [.clearCache](index.js#L806)
552
575
 
553
576
  Clear the regex cache.
554
577
 
@@ -957,59 +980,92 @@ npm i -d && npm run benchmark
957
980
 
958
981
  ### Latest results
959
982
 
960
- As of September 07, 2017 (longer bars are better):
983
+ As of September 11, 2017 (longer bars are better):
961
984
 
962
985
  ```sh
963
- # braces-globstar-large-list
964
- micromatch ██████████████████████████████████████████████████ (595 ops/sec)
965
- minimatch █ (13.95 ops/sec)
966
- multimatch █ (14.09 ops/sec)
967
-
968
- # braces-multiple
969
- micromatch ██████████████████████████████████████████████████ (48,362 ops/sec)
970
- minimatch (2.18 ops/sec)
971
- multimatch (2.15 ops/sec)
972
-
973
- # braces-range
974
- micromatch ██████████████████████████████████████████████████ (187,481 ops/sec)
975
- minimatch ███ (12,366 ops/sec)
976
- multimatch ███ (11,841 ops/sec)
977
-
978
- # braces-set
979
- micromatch ██████████████████████████████████████████████████ (24,344 ops/sec)
980
- minimatch ████ (2,255 ops/sec)
981
- multimatch ████ (2,199 ops/sec)
982
-
983
- # globstar-large-list
984
- micromatch ██████████████████████████████████████████████████ (561 ops/sec)
985
- minimatch ██ (25.43 ops/sec)
986
- multimatch ██ (25.27 ops/sec)
987
-
988
- # globstar-long-list
989
- micromatch ██████████████████████████████████████████████████ (3,257 ops/sec)
990
- minimatch ███████ (485 ops/sec)
991
- multimatch ███████ (485 ops/sec)
992
-
993
- # globstar-short-list
994
- micromatch ██████████████████████████████████████████████████ (359,991 ops/sec)
995
- minimatch ██████ (44,763 ops/sec)
996
- multimatch █████ (39,977 ops/sec)
997
-
998
- # no-glob
999
- micromatch ██████████████████████████████████████████████████ (443,740 ops/sec)
1000
- minimatch ████ (44,152 ops/sec)
1001
- multimatch ████ (41,077 ops/sec)
1002
-
1003
- # star-basename
1004
- micromatch ██████████████████████████████████████████████████ (10,286 ops/sec)
1005
- minimatch ██████████████ (3,059 ops/sec)
1006
- multimatch ███████████████ (3,129 ops/sec)
1007
-
1008
- # star
1009
- micromatch ██████████████████████████████████████████████████ (9,756 ops/sec)
1010
- minimatch ███████████████ (2,978 ops/sec)
1011
- multimatch ███████████████ (2,970 ops/sec)
986
+ # braces-globstar-large-list (485691 bytes)
987
+ micromatch ██████████████████████████████████████████████████ (517 ops/sec ±0.49%)
988
+ minimatch █ (18.92 ops/sec ±0.54%)
989
+ multimatch █ (18.94 ops/sec ±0.62%)
990
+
991
+ micromatch is faster by an avg. of 2,733%
992
+
993
+ # braces-multiple (3362 bytes)
994
+ micromatch ██████████████████████████████████████████████████ (33,625 ops/sec ±0.45%)
995
+ minimatch (2.92 ops/sec ±3.26%)
996
+ multimatch (2.90 ops/sec ±2.76%)
997
+
998
+ micromatch is faster by an avg. of 1,156,935%
999
+
1000
+ # braces-range (727 bytes)
1001
+ micromatch █████████████████████████████████████████████████ (155,220 ops/sec ±0.56%)
1002
+ minimatch ██████ (20,186 ops/sec ±1.27%)
1003
+ multimatch ██████ (19,809 ops/sec ±0.60%)
1004
+
1005
+ micromatch is faster by an avg. of 776%
1006
+
1007
+ # braces-set (2858 bytes)
1008
+ micromatch █████████████████████████████████████████████████ (24,354 ops/sec ±0.92%)
1009
+ minimatch █████ (2,566 ops/sec ±0.56%)
1010
+ multimatch ████ (2,431 ops/sec ±1.25%)
1011
+
1012
+ micromatch is faster by an avg. of 975%
1013
+
1014
+ # globstar-large-list (485686 bytes)
1015
+ micromatch █████████████████████████████████████████████████ (504 ops/sec ±0.45%)
1016
+ minimatch ███ (33.36 ops/sec ±1.08%)
1017
+ multimatch ███ (33.19 ops/sec ±1.35%)
1018
+
1019
+ micromatch is faster by an avg. of 1,514%
1020
+
1021
+ # globstar-long-list (90647 bytes)
1022
+ micromatch ██████████████████████████████████████████████████ (2,694 ops/sec ±1.08%)
1023
+ minimatch ████████████████ (870 ops/sec ±1.09%)
1024
+ multimatch ████████████████ (862 ops/sec ±0.84%)
1025
+
1026
+ micromatch is faster by an avg. of 311%
1027
+
1028
+ # globstar-short-list (182 bytes)
1029
+ micromatch ██████████████████████████████████████████████████ (328,921 ops/sec ±1.06%)
1030
+ minimatch █████████ (64,808 ops/sec ±1.42%)
1031
+ multimatch ████████ (57,991 ops/sec ±2.11%)
1032
+
1033
+ micromatch is faster by an avg. of 536%
1034
+
1035
+ # no-glob (701 bytes)
1036
+ micromatch █████████████████████████████████████████████████ (415,935 ops/sec ±0.36%)
1037
+ minimatch ███████████ (92,730 ops/sec ±1.44%)
1038
+ multimatch █████████ (81,958 ops/sec ±2.13%)
1039
+
1040
+ micromatch is faster by an avg. of 476%
1041
+
1042
+ # star-basename-long (12339 bytes)
1043
+ micromatch █████████████████████████████████████████████████ (7,963 ops/sec ±0.36%)
1044
+ minimatch ███████████████████████████████ (5,072 ops/sec ±0.83%)
1045
+ multimatch ███████████████████████████████ (5,028 ops/sec ±0.40%)
1046
+
1047
+ micromatch is faster by an avg. of 158%
1048
+
1049
+ # star-basename-short (349 bytes)
1050
+ micromatch ██████████████████████████████████████████████████ (269,552 ops/sec ±0.70%)
1051
+ minimatch ██████████████████████ (122,457 ops/sec ±1.39%)
1052
+ multimatch ████████████████████ (110,788 ops/sec ±1.99%)
1053
+
1054
+ micromatch is faster by an avg. of 231%
1055
+
1056
+ # star-folder-long (19207 bytes)
1057
+ micromatch █████████████████████████████████████████████████ (3,806 ops/sec ±0.38%)
1058
+ minimatch ████████████████████████████ (2,204 ops/sec ±0.32%)
1059
+ multimatch ██████████████████████████ (2,020 ops/sec ±1.07%)
1060
+
1061
+ micromatch is faster by an avg. of 180%
1062
+
1063
+ # star-folder-short (551 bytes)
1064
+ micromatch ██████████████████████████████████████████████████ (249,077 ops/sec ±0.40%)
1065
+ minimatch ███████████ (59,431 ops/sec ±1.67%)
1066
+ multimatch ███████████ (55,569 ops/sec ±1.43%)
1012
1067
 
1068
+ micromatch is faster by an avg. of 433%
1013
1069
  ```
1014
1070
 
1015
1071
  ## About
@@ -1034,7 +1090,7 @@ Please read the [contributing guide](.github/contributing.md) for advice on open
1034
1090
 
1035
1091
  | **Commits** | **Contributor** |
1036
1092
  | --- | --- |
1037
- | 430 | [jonschlinkert](https://github.com/jonschlinkert) |
1093
+ | 439 | [jonschlinkert](https://github.com/jonschlinkert) |
1038
1094
  | 12 | [es128](https://github.com/es128) |
1039
1095
  | 8 | [doowb](https://github.com/doowb) |
1040
1096
  | 3 | [paulmillr](https://github.com/paulmillr) |
@@ -1079,4 +1135,4 @@ Released under the [MIT License](LICENSE).
1079
1135
 
1080
1136
  ***
1081
1137
 
1082
- _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 07, 2017._
1138
+ _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 11, 2017._
package/index.js CHANGED
@@ -514,6 +514,44 @@ micromatch.matcher = function matcher(pattern, options) {
514
514
  return fn;
515
515
  };
516
516
 
517
+ /**
518
+ * Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
519
+ *
520
+ * ```js
521
+ * var mm = require('micromatch');
522
+ * mm.capture(pattern, string[, options]);
523
+ *
524
+ * console.log(mm.capture('test/*.js', 'test/foo.js));
525
+ * //=> ['foo']
526
+ * console.log(mm.capture('test/*.js', 'foo/bar.css'));
527
+ * //=> null
528
+ * ```
529
+ * @param {String} `pattern` Glob pattern to use for matching.
530
+ * @param {String} `string` String to match
531
+ * @param {Object} `options` See available [options](#options) for changing how matches are performed
532
+ * @return {Boolean} Returns an array of captures if the string matches the glob pattern, otherwise `null`.
533
+ * @api public
534
+ */
535
+
536
+ micromatch.capture = function(pattern, str, options) {
537
+ var re = micromatch.makeRe(pattern, extend({capture: true}, options));
538
+ var unixify = utils.unixify(options);
539
+
540
+ function match() {
541
+ return function(string) {
542
+ var match = re.exec(unixify(string));
543
+ if (!match) {
544
+ return null;
545
+ }
546
+
547
+ return match.slice(1);
548
+ };
549
+ }
550
+
551
+ var capture = memoize('capture', pattern, options, match);
552
+ return capture(str);
553
+ };
554
+
517
555
  /**
518
556
  * Create a regular expression from the given glob `pattern`.
519
557
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "micromatch",
3
3
  "description": "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.",
4
- "version": "3.0.5",
4
+ "version": "3.1.0",
5
5
  "homepage": "https://github.com/micromatch/micromatch",
6
6
  "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7
7
  "contributors": [
@@ -40,7 +40,7 @@
40
40
  "braces": "^2.2.2",
41
41
  "define-property": "^1.0.0",
42
42
  "extend-shallow": "^2.0.1",
43
- "extglob": "^2.0.0",
43
+ "extglob": "^2.0.2",
44
44
  "fragment-cache": "^0.2.1",
45
45
  "kind-of": "^5.0.2",
46
46
  "nanomatch": "^1.2.1",