Comparing version 0.3.1 to 0.3.3
@@ -109,3 +109,3 @@ 'use strict'; | ||
var unixify = utils.unixify(options); | ||
var isMatch = nanomatch.matcher(pattern, options); | ||
var isMatch = memoize('match', pattern, options, nanomatch.matcher); | ||
@@ -112,0 +112,0 @@ list = utils.arrayify(list); |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var star = '[^\\\\/]*?'; | ||
var appended = false; | ||
@@ -65,8 +66,9 @@ nanomatch.state = nanomatch.state || {}; | ||
} | ||
if (node.parsed === '**' || node.parsed === './**') { | ||
this.output = '(' + this.output; | ||
return this.emit('\\/)*', node); | ||
return this.emit('\\/|^)', node); | ||
} | ||
if (node.parsed === '!**') { | ||
return this.emit('\\/*', node); | ||
return this.emit('\\/?\\b', node); | ||
} | ||
@@ -185,3 +187,3 @@ return this.emit('\\/', node); | ||
if (type === 'slash' && node.rest.charAt(0) === '/' && prior.type !== 'qmark') { | ||
this.output += '?'; | ||
this.output += '?\\b'; | ||
} | ||
@@ -233,4 +235,6 @@ | ||
if (node.rest === '') { | ||
val += '\\/?'; | ||
appended = true; | ||
val += (this.options.contains ? '\\/?' : '(\\/|$)'); | ||
} | ||
return this.emit(val, node); | ||
@@ -245,4 +249,4 @@ }) | ||
var val = node.val; | ||
if (node.rest === '' && nanomatch.state.metachar) { | ||
val += '\\/?'; | ||
if (!appended && node.rest === '' && nanomatch.state.metachar) { | ||
val += (this.options.contains ? '\\/?' : '(\\/|$)'); | ||
} | ||
@@ -249,0 +253,0 @@ return this.emit(val, node); |
@@ -100,3 +100,3 @@ 'use strict'; | ||
utils.hasSpecialChars = function(str) { | ||
return /(?:(^|\/)[!.]|[*?+()|\[\]{}]|[+@]\()/.test(str); | ||
return /(?:(?:(^|\/)[!.])|[*?+()|\[\]{}]|[+@]\()/.test(str); | ||
}; | ||
@@ -218,6 +218,8 @@ | ||
if (fp.charAt(0) === '.' && (fp.charAt(1) === '/' || fp.charAt(1) === '\\')) { | ||
var ch0 = fp.charAt(0); | ||
var ch1 = fp.charAt(1); | ||
if (ch0 === '.' && (ch1 === '/' || ch1 === '\\')) { | ||
return fp.slice(2); | ||
} | ||
return fp; | ||
@@ -238,4 +240,2 @@ }; | ||
var opts = utils.extend({}, options); | ||
var unixify = function(filepath) { | ||
@@ -245,3 +245,4 @@ return utils.stripPrefix(filepath); | ||
if (path.sep !== '/' || opts.unixify === true || opts.normalize === true) { | ||
options = options || {}; | ||
if (path.sep !== '/' || options.unixify === true || options.normalize === true) { | ||
unixify = function(filepath) { | ||
@@ -252,3 +253,3 @@ return utils.stripPrefix(utils.normalize(filepath)); | ||
if (opts.unescape === true) { | ||
if (options.unescape === true) { | ||
unixify = function(filepath) { | ||
@@ -255,0 +256,0 @@ return utils.stripPrefix(utils.normalize(utils.unescape(filepath))); |
{ | ||
"name": "nanomatch", | ||
"description": "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)", | ||
"version": "0.3.1", | ||
"version": "0.3.3", | ||
"homepage": "https://github.com/jonschlinkert/nanomatch", | ||
@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", |
188
README.md
@@ -72,3 +72,3 @@ # nanomatch [![NPM version](https://img.shields.io/npm/v/nanomatch.svg?style=flat)](https://www.npmjs.com/package/nanomatch) [![NPM monthly downloads](https://img.shields.io/npm/dm/nanomatch.svg?style=flat)](https://npmjs.org/package/nanomatch) [![NPM total downloads](https://img.shields.io/npm/dt/nanomatch.svg?style=flat)](https://npmjs.org/package/nanomatch) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/nanomatch.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/nanomatch) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/nanomatch.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/nanomatch) | ||
### [nanomatch](index.js#L37) | ||
### [nanomatch](index.js#L39) | ||
@@ -80,4 +80,6 @@ The main function takes a list of strings and one or more glob patterns to use for matching. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch(['a.js', 'a.txt'], ['*.js'])); | ||
var mm = require('nanomatch'); | ||
mm(list, patterns[, options]); | ||
console.log(mm(['a.js', 'a.txt'], ['*.js'])); | ||
//=> [ 'a.js' ] | ||
@@ -88,8 +90,8 @@ ``` | ||
* `list` **{Array}** | ||
* `patterns` **{String|Array}**: Glob patterns | ||
* `options` **{Object}** | ||
* `list` **{Array}**: A list of strings to match | ||
* `patterns` **{String|Array}**: One or more glob patterns to use for matching. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Array}**: Returns an array of matches | ||
### [.match](index.js#L103) | ||
### [.match](index.js#L107) | ||
@@ -101,4 +103,6 @@ Similar to the main function, but `pattern` must be a string. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.match(['a.a', 'a.aa', 'a.b', 'a.c'], '*.a')); | ||
var mm = require('nanomatch'); | ||
mm.match(list, pattern[, options]); | ||
console.log(mm.match(['a.a', 'a.aa', 'a.b', 'a.c'], '*.a')); | ||
//=> ['a.a', 'a.aa'] | ||
@@ -110,7 +114,7 @@ ``` | ||
* `list` **{Array}**: Array of strings to match | ||
* `pattern` **{String}**: Glob pattern | ||
* `options` **{Object}** | ||
* `pattern` **{String}**: Glob pattern to use for matching. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Array}**: Returns an array of matches | ||
### [.isMatch](index.js#L165) | ||
### [.isMatch](index.js#L171) | ||
@@ -122,6 +126,8 @@ Returns true if the specified `string` matches the given glob `pattern`. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.isMatch('a.a', '*.a')); | ||
var mm = require('nanomatch'); | ||
mm.isMatch(string, pattern[, options]); | ||
console.log(mm.isMatch('a.a', '*.a')); | ||
//=> true | ||
console.log(nanomatch.isMatch('a.b', '*.a')); | ||
console.log(mm.isMatch('a.b', '*.a')); | ||
//=> false | ||
@@ -133,9 +139,9 @@ ``` | ||
* `string` **{String}**: String to match | ||
* `pattern` **{String}**: Glob pattern | ||
* `options` **{String}** | ||
* `pattern` **{String}**: Glob pattern to use for matching. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Boolean}**: Returns true if the string matches the glob pattern. | ||
### [.not](index.js#L192) | ||
### [.not](index.js#L200) | ||
Returns a list of strings that do _not_ match any of the given `patterns`. | ||
Returns a list of strings that _DO NOT MATCH_ any of the given `patterns`. | ||
@@ -145,4 +151,6 @@ **Example** | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.not(['a.a', 'b.b', 'c.c'], '*.a')); | ||
var mm = require('nanomatch'); | ||
mm.not(list, patterns[, options]); | ||
console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a')); | ||
//=> ['b.b', 'c.c'] | ||
@@ -154,7 +162,7 @@ ``` | ||
* `list` **{Array}**: Array of strings to match. | ||
* `pattern` **{String}**: One or more glob patterns. | ||
* `options` **{Object}** | ||
* `returns` **{Array}**: Returns an array of strings that do not match the given patterns. | ||
* `patterns` **{String|Array}**: One or more glob pattern to use for matching. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Array}**: Returns an array of strings that **do not match** the given patterns. | ||
### [.any](index.js#L227) | ||
### [.any](index.js#L237) | ||
@@ -166,6 +174,8 @@ Returns true if the given `string` matches any of the given glob `patterns`. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.any('a.a', ['b.*', '*.a'])); | ||
var mm = require('nanomatch'); | ||
mm.any(string, patterns[, options]); | ||
console.log(mm.any('a.a', ['b.*', '*.a'])); | ||
//=> true | ||
console.log(nanomatch.any('a.a', 'b.*')); | ||
console.log(mm.any('a.a', 'b.*')); | ||
//=> false | ||
@@ -177,9 +187,9 @@ ``` | ||
* `str` **{String}**: The string to test. | ||
* `patterns` **{String|Array}**: Glob patterns to use. | ||
* `options` **{Object}**: Options to pass to the `matcher()` function. | ||
* `patterns` **{String|Array}**: One or more glob patterns to use for matching. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Boolean}**: Returns true if any patterns match `str` | ||
### [.contains](index.js#L255) | ||
### [.contains](index.js#L267) | ||
Returns true if the given `string` contains the given pattern. Similar to `.isMatch` but the pattern can match any part of the string. | ||
Returns true if the given `string` contains the given pattern. Similar to [.isMatch](#isMatch) but the pattern can match any part of the string. | ||
@@ -189,6 +199,8 @@ **Example** | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.contains('aa/bb/cc', '*b')); | ||
var mm = require('nanomatch'); | ||
mm.contains(string, pattern[, options]); | ||
console.log(mm.contains('aa/bb/cc', '*b')); | ||
//=> true | ||
console.log(nanomatch.contains('aa/bb/cc', '*d')); | ||
console.log(mm.contains('aa/bb/cc', '*d')); | ||
//=> false | ||
@@ -201,6 +213,6 @@ ``` | ||
* `pattern` **{String}**: Glob pattern to use for matching. | ||
* `options` **{Object}** | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Boolean}**: Returns true if the patter matches any part of `str`. | ||
### [.matchKeys](index.js#L295) | ||
### [.matchKeys](index.js#L316) | ||
@@ -212,5 +224,7 @@ 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. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
var mm = require('nanomatch'); | ||
mm.matchKeys(object, patterns[, options]); | ||
var obj = { aa: 'a', ab: 'b', ac: 'c' }; | ||
console.log(nanomatch.matchKeys(obj, '*b')); | ||
console.log(mm.matchKeys(obj, '*b')); | ||
//=> { ab: 'b' } | ||
@@ -221,9 +235,10 @@ ``` | ||
* `object` **{Object}** | ||
* `patterns` **{Array|String}**: One or more glob patterns. | ||
* `object` **{Object}**: The object with keys to filter. | ||
* `patterns` **{String|Array}**: One or more glob patterns to use for matching. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed | ||
* `returns` **{Object}**: Returns an object with only keys that match the given patterns. | ||
### [.matcher](index.js#L322) | ||
### [.matcher](index.js#L345) | ||
Creates a matcher function from the given glob `pattern` and `options`. The returned function takes a string to match as its only argument. | ||
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. | ||
@@ -233,5 +248,6 @@ **Example** | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
var isMatch = nanomatch.matcher('*.!(*a)'); | ||
var mm = require('nanomatch'); | ||
mm.matcher(pattern[, options]); | ||
var isMatch = mm.matcher('*.!(*a)'); | ||
console.log(isMatch('a.a')); | ||
@@ -246,6 +262,6 @@ //=> false | ||
* `pattern` **{String}**: Glob pattern | ||
* `options` **{String}** | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed. | ||
* `returns` **{Function}**: Returns a matcher function. | ||
### [.makeRe](index.js#L377) | ||
### [.makeRe](index.js#L402) | ||
@@ -257,4 +273,6 @@ Create a regular expression from the given glob `pattern`. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.makeRe('*.js')); | ||
var mm = require('nanomatch'); | ||
mm.makeRe(pattern[, options]); | ||
console.log(mm.makeRe('*.js')); | ||
//=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/ | ||
@@ -265,7 +283,7 @@ ``` | ||
* `pattern` **{String}**: The pattern to convert to regex. | ||
* `options` **{Object}** | ||
* `pattern` **{String}**: A glob pattern to convert to regex. | ||
* `options` **{Object}**: Any [options](#options) to change how matches are performed. | ||
* `returns` **{RegExp}**: Returns a regex created from the given pattern. | ||
### [.create](index.js#L435) | ||
### [.create](index.js#L462) | ||
@@ -277,4 +295,6 @@ Parses the given glob `pattern` and returns an object with the compiled `output` and optional source `map`. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
console.log(nanomatch.create('abc/*.js')); | ||
var mm = require('nanomatch'); | ||
mm.create(pattern[, options]); | ||
console.log(mm.create('abc/*.js')); | ||
// { options: { source: 'string', sourcemap: true }, | ||
@@ -307,7 +327,7 @@ // state: {}, | ||
* `pattern` **{String}**: Glob pattern | ||
* `options` **{Object}** | ||
* `pattern` **{String}**: Glob pattern to parse and compile. | ||
* `options` **{Object}**: Any [options](#options) to change how parsing and compiling is performed. | ||
* `returns` **{Object}**: Returns an object with the parsed AST, compiled string and optional source map. | ||
### [.parse](index.js#L472) | ||
### [.parse](index.js#L501) | ||
@@ -319,4 +339,6 @@ Parse the given `str` with the given `options`. | ||
```js | ||
var nanomatch = require('nanomatch'); | ||
var ast = nanomatch.parse('a/{b,c}/d'); | ||
var mm = require('nanomatch'); | ||
mm.parse(pattern[, options]); | ||
var ast = mm.parse('a/{b,c}/d'); | ||
console.log(ast); | ||
@@ -344,3 +366,3 @@ // { type: 'root', | ||
### [.compile](index.js#L523) | ||
### [.compile](index.js#L554) | ||
@@ -353,2 +375,4 @@ Compile the given `ast` or string with the given `options`. | ||
var nanomatch = require('nanomatch'); | ||
mm.compile(ast[, options]); | ||
var ast = nanomatch.parse('a/{b,c}/d'); | ||
@@ -436,4 +460,6 @@ console.log(nanomatch.compile(ast)); | ||
```bash | ||
Benchmarking: (4 of 4) | ||
Benchmarking: (6 of 6) | ||
· globstar-basic | ||
· large-list-globstar | ||
· long-list-globstar | ||
· negation-basic | ||
@@ -444,12 +470,26 @@ · not-glob-basic | ||
# benchmark/fixtures/match/globstar-basic.js (182 bytes) | ||
minimatch x 35,521 ops/sec ±0.99% (82 runs sampled) | ||
multimatch x 29,662 ops/sec ±1.90% (82 runs sampled) | ||
nanomatch x 719,866 ops/sec ±1.53% (84 runs sampled) | ||
minimatch x 32,012 ops/sec ±0.86% (83 runs sampled) | ||
multimatch x 29,055 ops/sec ±1.41% (83 runs sampled) | ||
nanomatch x 479,001 ops/sec ±1.32% (86 runs sampled) | ||
fastest is nanomatch | ||
# benchmark/fixtures/match/large-list-globstar.js (485686 bytes) | ||
minimatch x 24.10 ops/sec ±1.28% (42 runs sampled) | ||
multimatch x 24.33 ops/sec ±0.78% (44 runs sampled) | ||
nanomatch x 407 ops/sec ±0.86% (83 runs sampled) | ||
fastest is nanomatch | ||
# benchmark/fixtures/match/long-list-globstar.js (194085 bytes) | ||
minimatch x 264 ops/sec ±1.13% (82 runs sampled) | ||
multimatch x 251 ops/sec ±0.96% (82 runs sampled) | ||
nanomatch x 999 ops/sec ±0.51% (87 runs sampled) | ||
fastest is nanomatch | ||
# benchmark/fixtures/match/negation-basic.js (132 bytes) | ||
minimatch x 65,810 ops/sec ±1.11% (85 runs sampled) | ||
multimatch x 24,267 ops/sec ±1.40% (85 runs sampled) | ||
nanomatch x 698,260 ops/sec ±1.42% (84 runs sampled) | ||
minimatch x 77,301 ops/sec ±1.68% (85 runs sampled) | ||
multimatch x 25,492 ops/sec ±1.24% (86 runs sampled) | ||
nanomatch x 565,552 ops/sec ±1.16% (88 runs sampled) | ||
@@ -459,5 +499,5 @@ fastest is nanomatch | ||
# benchmark/fixtures/match/not-glob-basic.js (93 bytes) | ||
minimatch x 91,445 ops/sec ±1.69% (83 runs sampled) | ||
multimatch x 62,945 ops/sec ±1.20% (84 runs sampled) | ||
nanomatch x 3,077,100 ops/sec ±1.45% (84 runs sampled) | ||
minimatch x 90,972 ops/sec ±1.02% (86 runs sampled) | ||
multimatch x 71,725 ops/sec ±1.42% (86 runs sampled) | ||
nanomatch x 1,446,237 ops/sec ±0.99% (87 runs sampled) | ||
@@ -467,5 +507,5 @@ fastest is nanomatch | ||
# benchmark/fixtures/match/star-basic.js (93 bytes) | ||
minimatch x 62,144 ops/sec ±1.67% (85 runs sampled) | ||
multimatch x 46,133 ops/sec ±1.66% (83 runs sampled) | ||
nanomatch x 1,039,345 ops/sec ±1.23% (86 runs sampled) | ||
minimatch x 70,011 ops/sec ±1.23% (87 runs sampled) | ||
multimatch x 53,431 ops/sec ±1.07% (89 runs sampled) | ||
nanomatch x 650,425 ops/sec ±0.85% (90 runs sampled) | ||
@@ -528,2 +568,2 @@ fastest is nanomatch | ||
_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.2.0, on October 21, 2016._ |
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
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
56907
1194
540