multimatch
Advanced tools
Comparing version 0.2.0 to 0.3.0
15
index.js
'use strict'; | ||
var minimatch = require('minimatch'); | ||
var _ = require('lodash'); | ||
var union = require('array-union'); | ||
var diff = require('array-differ'); | ||
@@ -10,3 +11,6 @@ function arrayify(arr) { | ||
module.exports = function (list, patterns, options) { | ||
if (list == null || patterns == null) { | ||
list = arrayify(list); | ||
patterns = arrayify(patterns); | ||
if (list.length === 0 || patterns.length === 0) { | ||
return []; | ||
@@ -16,13 +20,10 @@ } | ||
options = options || {}; | ||
list = arrayify(list); | ||
patterns = arrayify(patterns); | ||
return patterns.reduce(function (ret, pattern, i) { | ||
if (pattern[0] === '!') { | ||
ret = i === 0 ? list : ret; | ||
return _.difference(ret, minimatch.match(ret, pattern.slice(1), options)); | ||
return diff(ret, minimatch.match(ret, pattern.slice(1), options)); | ||
} | ||
return _.union(ret, minimatch.match(list, pattern, options)); | ||
return union(ret, minimatch.match(list, pattern, options)); | ||
}, []); | ||
}; |
{ | ||
"name": "multimatch", | ||
"version": "0.2.0", | ||
"description": "Adds multiple patterns support to minimatch.match()", | ||
"version": "0.3.0", | ||
"description": "Extends minimatch.match() with support for multiple patterns", | ||
"license": "MIT", | ||
@@ -12,2 +12,8 @@ "repository": "sindresorhus/multimatch", | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
} | ||
], | ||
"engines": { | ||
@@ -29,13 +35,17 @@ "node": ">=0.10.0" | ||
"glob", | ||
"globs", | ||
"globbing", | ||
"expand", | ||
"wildcard" | ||
"wildcard", | ||
"find" | ||
], | ||
"dependencies": { | ||
"lodash": "^2.4.1", | ||
"array-differ": "^0.1.0", | ||
"array-union": "^0.1.0", | ||
"minimatch": "^0.3.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"mocha": "*" | ||
} | ||
} |
# multimatch [![Build Status](https://travis-ci.org/sindresorhus/multimatch.svg?branch=master)](https://travis-ci.org/sindresorhus/multimatch) | ||
> Adds multiple patterns support to [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) | ||
> Extends [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) with support for multiple patterns | ||
@@ -23,3 +23,4 @@ | ||
```bash | ||
```sh | ||
$ npm install --save multimatch | ||
@@ -34,8 +35,6 @@ ``` | ||
multimatch(['unicorn', 'cake', 'rainbows'], ['!cake', '*corn'])); | ||
multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']); | ||
//=> ['unicorn', 'rainbows'] | ||
``` | ||
Patterns are additive while negations (eg `['foo', '!bar']`) are based on the current set. Exception is if the first pattern is negation, then it will get the full set, so to match user expectation (eg. `['!foo']` will match everything except `foo`). Order matters. | ||
See the [tests](https://github.com/sindresorhus/multimatch/blob/master/test.js) for more usage examples and expected matches. | ||
@@ -51,2 +50,2 @@ | ||
[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](http://sindresorhus.com), [Jon Schlinkert](https://github.com/jonschlinkert) |
2617
3
2
49
+ Addedarray-differ@^0.1.0
+ Addedarray-union@^0.1.0
+ Addedarray-differ@0.1.0(transitive)
+ Addedarray-union@0.1.0(transitive)
+ Addedarray-uniq@0.1.1(transitive)
- Removedlodash@^2.4.1
- Removedlodash@2.4.2(transitive)