Comparing version 1.1.0 to 2.0.0
## Changelog | ||
### v2.0.0 | ||
**Added features** | ||
- Adds [.capture](readme.md#capture) method for capturing matches, thanks to [devongovett](https://github.com/devongovett) | ||
### v1.0.0 | ||
@@ -4,0 +11,0 @@ |
55
index.js
@@ -41,11 +41,2 @@ 'use strict'; | ||
/** | ||
* Cache | ||
*/ | ||
extglob.cache = utils.cache; | ||
extglob.clearCache = function() { | ||
extglob.cache.__data__ = {}; | ||
}; | ||
/** | ||
* Takes an array of strings and an extglob pattern and returns a new | ||
@@ -239,2 +230,39 @@ * array that contains only the strings that match the pattern. | ||
/** | ||
* Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match. | ||
* | ||
* ```js | ||
* var extglob = require('extglob'); | ||
* extglob.capture(pattern, string[, options]); | ||
* | ||
* console.log(extglob.capture('test/*.js', 'test/foo.js)); | ||
* //=> ['foo'] | ||
* console.log(extglob.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 | ||
*/ | ||
extglob.capture = function(pattern, str, options) { | ||
var re = extglob.makeRe(pattern, extend({capture: true}, options)); | ||
function match() { | ||
return function(string) { | ||
var match = re.exec(string); | ||
if (!match) { | ||
return null; | ||
} | ||
return match.slice(1); | ||
}; | ||
} | ||
var capture = utils.memoize('capture', pattern, options, match); | ||
return capture(str); | ||
}; | ||
/** | ||
* Create a regular expression from the given `pattern` and `options`. | ||
@@ -283,2 +311,11 @@ * | ||
/** | ||
* Cache | ||
*/ | ||
extglob.cache = utils.cache; | ||
extglob.clearCache = function() { | ||
extglob.cache.__data__ = {}; | ||
}; | ||
/** | ||
* Expose `Extglob` constructor, parsers and compilers | ||
@@ -285,0 +322,0 @@ */ |
@@ -109,6 +109,8 @@ 'use strict'; | ||
.set('paren.open', function(node) { | ||
var capture = this.options.capture ? '(' : ''; | ||
switch (node.parent.prefix) { | ||
case '!': | ||
case '^': | ||
return this.emit('(?:(?!(?:', node); | ||
return this.emit(capture + '(?:(?!(?:', node); | ||
case '*': | ||
@@ -118,5 +120,11 @@ case '+': | ||
case '@': | ||
return this.emit('(', node); | ||
return this.emit(capture + '(?:', node); | ||
default: { | ||
var val = (this.options.bash === true ? '\\' : '') + node.val; | ||
var val = node.val; | ||
if (this.options.bash === true) { | ||
val = '\\' + val; | ||
} else if (!this.options.capture && val === '(' && node.parent.rest[0] !== '?') { | ||
val += '?:'; | ||
} | ||
return this.emit(val, node); | ||
@@ -127,2 +135,4 @@ } | ||
.set('paren.close', function(node) { | ||
var capture = this.options.capture ? ')' : ''; | ||
switch (node.prefix) { | ||
@@ -135,3 +145,3 @@ case '!': | ||
// if the extglob has a slash explicitly defined, we know the user wants | ||
// to match slashes, so we need to change the "star" regex accordingly | ||
// to match slashes, so we need to ensure the "star" regex allows for it | ||
if (node.parent.hasSlash && !this.options.star && this.options.slash !== false) { | ||
@@ -141,11 +151,9 @@ str = '.*?'; | ||
return this.emit(prefix + ('))' + str + ')'), node); | ||
return this.emit(prefix + ('))' + str + ')') + capture, node); | ||
case '*': | ||
case '+': | ||
return this.emit(')+', node); | ||
case '*': | ||
return this.emit(')*', node); | ||
case '?': | ||
return this.emit(')?', node); | ||
return this.emit(')' + node.prefix + capture, node); | ||
case '@': | ||
return this.emit(')', node); | ||
return this.emit(')' + capture, node); | ||
default: { | ||
@@ -152,0 +160,0 @@ var val = (this.options.bash === true ? '\\' : '') + ')'; |
{ | ||
"name": "extglob", | ||
"description": "Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/jonschlinkert/extglob", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/micromatch/extglob", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"contributors": [ | ||
"Isiah Meadows <me@isiahmeadows.com> (https://www.isiahmeadows.com)", | ||
"Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)", | ||
"Shinnosuke Watanabe <snnskwtnb@gmail.com> (https://shinnn.github.io)" | ||
"Brian Woodward (https://twitter.com/doowb)", | ||
"Devon Govett (http://badassjs.com)", | ||
"Isiah Meadows (https://www.isiahmeadows.com)", | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)", | ||
"Matt Bierner (http://mattbierner.com)", | ||
"Shinnosuke Watanabe (https://shinnn.github.io)" | ||
], | ||
"repository": "jonschlinkert/extglob", | ||
"repository": "micromatch/extglob", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/extglob/issues" | ||
"url": "https://github.com/micromatch/extglob/issues" | ||
}, | ||
@@ -30,26 +33,26 @@ "license": "MIT", | ||
"array-unique": "^0.3.2", | ||
"define-property": "^0.2.5", | ||
"expand-brackets": "^2.0.1", | ||
"define-property": "^1.0.0", | ||
"expand-brackets": "^2.1.4", | ||
"extend-shallow": "^2.0.1", | ||
"fragment-cache": "^0.2.0", | ||
"fragment-cache": "^0.2.1", | ||
"regex-not": "^1.0.0", | ||
"snapdragon": "^0.8.1", | ||
"to-regex": "^2.1.0" | ||
"to-regex": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
"bash-match": "^0.1.1", | ||
"for-own": "^0.1.4", | ||
"bash-match": "^1.0.2", | ||
"for-own": "^1.0.0", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-format-md": "^0.1.11", | ||
"gulp-istanbul": "^1.1.1", | ||
"gulp-eslint": "^4.0.0", | ||
"gulp-format-md": "^1.0.0", | ||
"gulp-istanbul": "^1.1.2", | ||
"gulp-mocha": "^3.0.1", | ||
"gulp-unused": "^0.2.0", | ||
"gulp-unused": "^0.2.1", | ||
"helper-changelog": "^0.3.0", | ||
"is-windows": "^0.2.0", | ||
"micromatch": "^2.3.11", | ||
"minimatch": "^3.0.3", | ||
"mocha": "^3.1.2", | ||
"is-windows": "^1.0.1", | ||
"micromatch": "^3.0.4", | ||
"minimatch": "^3.0.4", | ||
"mocha": "^3.5.0", | ||
"multimatch": "^2.1.0", | ||
"yargs-parser": "^4.0.2" | ||
"yargs-parser": "^7.0.0" | ||
}, | ||
@@ -70,2 +73,13 @@ "keywords": [ | ||
], | ||
"lintDeps": { | ||
"devDependencies": { | ||
"files": { | ||
"options": { | ||
"ignore": [ | ||
"benchmark/**/*.js" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"verb": { | ||
@@ -94,8 +108,4 @@ "toc": false, | ||
"reflinks": true | ||
}, | ||
"reflinks": [ | ||
"verb", | ||
"verb-generate-readme" | ||
] | ||
} | ||
} | ||
} | ||
} |
189
README.md
@@ -1,5 +0,7 @@ | ||
# extglob [![NPM version](https://img.shields.io/npm/v/extglob.svg?style=flat)](https://www.npmjs.com/package/extglob) [![NPM monthly downloads](https://img.shields.io/npm/dm/extglob.svg?style=flat)](https://npmjs.org/package/extglob) [![NPM total downloads](https://img.shields.io/npm/dt/extglob.svg?style=flat)](https://npmjs.org/package/extglob) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/extglob.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/extglob) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/extglob.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/extglob) | ||
# extglob [![NPM version](https://img.shields.io/npm/v/extglob.svg?style=flat)](https://www.npmjs.com/package/extglob) [![NPM monthly downloads](https://img.shields.io/npm/dm/extglob.svg?style=flat)](https://npmjs.org/package/extglob) [![NPM total downloads](https://img.shields.io/npm/dt/extglob.svg?style=flat)](https://npmjs.org/package/extglob) [![Linux Build Status](https://img.shields.io/travis/micromatch/extglob.svg?style=flat&label=Travis)](https://travis-ci.org/micromatch/extglob) [![Windows Build Status](https://img.shields.io/appveyor/ci/micromatch/extglob.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/micromatch/extglob) | ||
> Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns. | ||
Follow this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), for updates on this project and others. | ||
## Install | ||
@@ -45,6 +47,12 @@ | ||
### [extglob](index.js#L37) | ||
### [extglob](index.js#L36) | ||
Convert the given `extglob` pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST. | ||
**Params** | ||
* `pattern` **{String}** | ||
* `options` **{Object}** | ||
* `returns` **{String}** | ||
**Example** | ||
@@ -58,12 +66,13 @@ | ||
### [.match](index.js#L56) | ||
Takes an array of strings and an extglob pattern and returns a new array that contains only the strings that match the pattern. | ||
**Params** | ||
* `pattern` **{String}** | ||
* `list` **{Array}**: Array of strings to match | ||
* `pattern` **{String}**: Extglob pattern | ||
* `options` **{Object}** | ||
* `returns` **{String}** | ||
* `returns` **{Array}**: Returns an array of matches | ||
### [.match](index.js#L68) | ||
Takes an array of strings and an extglob pattern and returns a new array that contains only the strings that match the pattern. | ||
**Example** | ||
@@ -77,13 +86,13 @@ | ||
### [.isMatch](index.js#L111) | ||
Returns true if the specified `string` matches the given extglob `pattern`. | ||
**Params** | ||
* `list` **{Array}**: Array of strings to match | ||
* `string` **{String}**: String to match | ||
* `pattern` **{String}**: Extglob pattern | ||
* `options` **{Object}** | ||
* `returns` **{Array}**: Returns an array of matches | ||
* `options` **{String}** | ||
* `returns` **{Boolean}** | ||
### [.isMatch](index.js#L123) | ||
Returns true if the specified `string` matches the given extglob `pattern`. | ||
**Example** | ||
@@ -100,12 +109,12 @@ | ||
**Params** | ||
### [.contains](index.js#L150) | ||
* `string` **{String}**: String to match | ||
* `pattern` **{String}**: Extglob pattern | ||
* `options` **{String}** | ||
* `returns` **{Boolean}** | ||
Returns true if the given `string` contains the given pattern. Similar to `.isMatch` but the pattern can match any part of the string. | ||
### [.contains](index.js#L162) | ||
**Params** | ||
Returns true if the given `string` contains the given pattern. Similar to `.isMatch` but the pattern can match any part of the string. | ||
* `str` **{String}**: The string to match. | ||
* `pattern` **{String}**: Glob pattern to use for matching. | ||
* `options` **{Object}** | ||
* `returns` **{Boolean}**: Returns true if the patter matches any part of `str`. | ||
@@ -122,12 +131,11 @@ **Example** | ||
**Params** | ||
### [.matcher](index.js#L184) | ||
* `str` **{String}**: The string to match. | ||
* `pattern` **{String}**: Glob pattern to use for matching. | ||
* `options` **{Object}** | ||
* `returns` **{Boolean}**: Returns true if the patter matches any part of `str`. | ||
Takes an extglob pattern and returns a matcher function. The returned function takes the string to match as its only argument. | ||
### [.matcher](index.js#L196) | ||
**Params** | ||
Takes an extglob pattern and returns a matcher function. The returned function takes the string to match as its only argument. | ||
* `pattern` **{String}**: Extglob pattern | ||
* `options` **{String}** | ||
* `returns` **{Boolean}** | ||
@@ -146,11 +154,11 @@ **Example** | ||
**Params** | ||
### [.create](index.js#L214) | ||
* `pattern` **{String}**: Extglob pattern | ||
* `options` **{String}** | ||
* `returns` **{Boolean}** | ||
Convert the given `extglob` pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST. | ||
### [.create](index.js#L226) | ||
**Params** | ||
Convert the given `extglob` pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST. | ||
* `str` **{String}** | ||
* `options` **{Object}** | ||
* `returns` **{String}** | ||
@@ -165,11 +173,12 @@ **Example** | ||
**Params** | ||
### [.capture](index.js#L247) | ||
* `str` **{String}** | ||
* `options` **{Object}** | ||
* `returns` **{String}** | ||
Returns an array of matches captured by `pattern` in `string, or`null` if the pattern did not match. | ||
### [.makeRe](index.js#L255) | ||
**Params** | ||
Create a regular expression from the given `pattern` and `options`. | ||
* `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`. | ||
@@ -180,7 +189,14 @@ **Example** | ||
var extglob = require('extglob'); | ||
var re = extglob.makeRe('*.!(*a)'); | ||
console.log(re); | ||
//=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/ | ||
extglob.capture(pattern, string[, options]); | ||
console.log(extglob.capture('test/*.js', 'test/foo.js)); | ||
//=> ['foo'] | ||
console.log(extglob.capture('test/*.js', 'foo/bar.css')); | ||
//=> null | ||
``` | ||
### [.makeRe](index.js#L280) | ||
Create a regular expression from the given `pattern` and `options`. | ||
**Params** | ||
@@ -192,2 +208,11 @@ | ||
**Example** | ||
```js | ||
var extglob = require('extglob'); | ||
var re = extglob.makeRe('*.!(*a)'); | ||
console.log(re); | ||
//=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/ | ||
``` | ||
## Options | ||
@@ -227,41 +252,6 @@ | ||
Last run on October 20, 2016 | ||
Last run on September 07, 2017 | ||
```sh | ||
Benchmarking: (5 of 5) | ||
· negation-nested | ||
· negation-simple | ||
· range-false | ||
· range-true | ||
· star-simple | ||
# benchmark/fixtures/isMatch/negation-nested.js (49 bytes) | ||
extglob x 1,988,591 ops/sec ±1.18% (84 runs sampled) | ||
minimatch x 73,335 ops/sec ±1.38% (84 runs sampled) | ||
fastest is extglob | ||
# benchmark/fixtures/isMatch/negation-simple.js (43 bytes) | ||
extglob x 2,320,380 ops/sec ±1.71% (86 runs sampled) | ||
minimatch x 122,947 ops/sec ±1.28% (86 runs sampled) | ||
fastest is extglob | ||
# benchmark/fixtures/isMatch/range-false.js (56 bytes) | ||
extglob x 1,729,572 ops/sec ±1.22% (84 runs sampled) | ||
minimatch x 112,566 ops/sec ±1.26% (85 runs sampled) | ||
fastest is extglob | ||
# benchmark/fixtures/isMatch/range-true.js (56 bytes) | ||
extglob x 1,819,085 ops/sec ±1.28% (83 runs sampled) | ||
minimatch x 115,153 ops/sec ±1.50% (85 runs sampled) | ||
fastest is extglob | ||
# benchmark/fixtures/isMatch/star-simple.js (46 bytes) | ||
extglob x 1,970,063 ops/sec ±1.46% (83 runs sampled) | ||
minimatch x 138,805 ops/sec ±1.31% (87 runs sampled) | ||
fastest is extglob | ||
[object Object] | ||
``` | ||
@@ -280,7 +270,9 @@ | ||
* [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.") | ||
You might also be interested in these projects: | ||
* [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.") | ||
* [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.") | ||
* [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.") | ||
* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used… [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. Used by [micromatch].") | ||
* [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`") | ||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/jonschlinkert/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.") | ||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.") | ||
@@ -293,6 +285,9 @@ ### Contributing | ||
| **Commits** | **Contributor**<br/> | | ||
| --- | --- | --- | --- | --- | | ||
| 32 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 37 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 2 | [isiahmeadows](https://github.com/isiahmeadows) | | ||
| 1 | [doowb](https://github.com/doowb) | | ||
| 1 | [devongovett](https://github.com/devongovett) | | ||
| 1 | [mjbvz](https://github.com/mjbvz) | | ||
| 1 | [shinnn](https://github.com/shinnn) | | ||
@@ -302,8 +297,8 @@ | ||
_(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).)_ | ||
_(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.)_ | ||
To generate the readme and API documentation with [verb](https://github.com/verbose/verb): | ||
To generate the readme, run the following command: | ||
```sh | ||
$ npm install -g verb verb-generate-readme && verb | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
@@ -313,6 +308,6 @@ | ||
Install dev dependencies: | ||
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: | ||
```sh | ||
$ npm install -d && npm test | ||
$ npm install && npm test | ||
``` | ||
@@ -325,12 +320,12 @@ | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](https://github.com/jonschlinkert/extglob/blob/master/LICENSE). | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 20, 2016._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 07, 2017._ | ||
@@ -340,3 +335,3 @@ <hr class="footnotes-sep"> | ||
<ol class="footnotes-list"> | ||
<li id="fn1" class="footnote-item">`@` isn't a RegEx character. <a href="#fnref1" class="footnote-backref">↩</a> | ||
<li id="fn1" class="footnote-item">`@` isn "'t a RegEx character." <a href="#fnref1" class="footnote-backref">↩</a> | ||
@@ -343,0 +338,0 @@ </li> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
40005
10
661
324
1
- Removedregex-not@0.1.2(transitive)
- Removedto-regex@2.1.0(transitive)
Updateddefine-property@^1.0.0
Updatedexpand-brackets@^2.1.4
Updatedfragment-cache@^0.2.1
Updatedto-regex@^3.0.1