pax_global_header00006660000000000000000000000064126216362070014517gustar00rootroot0000000000000052 comment=5b56d1689ef475975682a514b8e1f863794af419 multimatch-2.1.0/000077500000000000000000000000001262163620700136665ustar00rootroot00000000000000multimatch-2.1.0/.editorconfig000066400000000000000000000003621262163620700163440ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [package.json] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false multimatch-2.1.0/.gitattributes000066400000000000000000000000141262163620700165540ustar00rootroot00000000000000* text=auto multimatch-2.1.0/.gitignore000066400000000000000000000000151262163620700156520ustar00rootroot00000000000000node_modules multimatch-2.1.0/.jshintrc000066400000000000000000000002761262163620700155200ustar00rootroot00000000000000{ "node": true, "esnext": true, "bitwise": true, "camelcase": true, "curly": true, "immed": true, "newcap": true, "noarg": true, "undef": true, "unused": "vars", "strict": true } multimatch-2.1.0/.travis.yml000066400000000000000000000001101262163620700157670ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'iojs' - '0.12' - '0.10' multimatch-2.1.0/index.js000066400000000000000000000011501262163620700153300ustar00rootroot00000000000000'use strict'; var minimatch = require('minimatch'); var arrayUnion = require('array-union'); var arrayDiffer = require('array-differ'); var arrify = require('arrify'); module.exports = function (list, patterns, options) { list = arrify(list); patterns = arrify(patterns); if (list.length === 0 || patterns.length === 0) { return []; } options = options || {}; return patterns.reduce(function (ret, pattern) { var process = arrayUnion; if (pattern[0] === '!') { pattern = pattern.slice(1); process = arrayDiffer; } return process(ret, minimatch.match(list, pattern, options)); }, []); }; multimatch-2.1.0/license000066400000000000000000000021221262163620700152300ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus, Jon Schlinkert, contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. multimatch-2.1.0/package.json000066400000000000000000000016411262163620700161560ustar00rootroot00000000000000{ "name": "multimatch", "version": "2.1.0", "description": "Extends minimatch.match() with support for multiple patterns", "license": "MIT", "repository": "sindresorhus/multimatch", "author": { "email": "sindresorhus@gmail.com", "name": "Sindre Sorhus", "url": "http://sindresorhus.com" }, "maintainers": [ { "name": "Jon Schlinkert", "url": "https://github.com/jonschlinkert" } ], "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "files": [ "index.js" ], "keywords": [ "expand", "find", "glob", "globbing", "globs", "match", "matcher", "minimatch", "pattern", "patterns", "wildcard" ], "dependencies": { "array-differ": "^1.0.0", "array-union": "^1.0.1", "arrify": "^1.0.0", "minimatch": "^3.0.0" }, "devDependencies": { "chai": "^3.4.1", "mocha": "*" } } multimatch-2.1.0/readme.md000066400000000000000000000033301262163620700154440ustar00rootroot00000000000000# multimatch [![Build Status](https://travis-ci.org/sindresorhus/multimatch.svg?branch=master)](https://travis-ci.org/sindresorhus/multimatch) > Extends [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) with support for multiple patterns ## Install ```sh $ npm install --save multimatch ``` ## Usage ```js var multimatch = require('multimatch'); multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']); //=> ['unicorn', 'rainbows'] ``` See the [tests](https://github.com/sindresorhus/multimatch/blob/master/test.js) for more usage examples and expected matches. ## API Same as [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) except for `pattern` also accepting an array. ```js var results = multimatch(paths, patterns); ``` The return value is an array of matching paths. ## How multiple patterns work Positive patterns (e.g. `foo` or `*`) add to the results, while negative patterns (e.g. `!foo`) subtract from the results. Therefore a lone negation (e.g. `['!foo']`) will never match anything – use `['*', '!foo']` instead. ## Globbing patterns Just a quick overview. - `*` matches any number of characters, but not `/` - `?` matches a single character, but not `/` - `**` matches any number of characters, including `/`, as long as it's the only thing in a path part - `{}` allows for a comma-separated list of "or" expressions - `!` at the beginning of a pattern will negate the match ## Related See [globby](https://github.com/sindresorhus/globby) if you need to match against the filesystem instead of a list. ## License MIT © [Sindre Sorhus](http://sindresorhus.com), [Jon Schlinkert](https://github.com/jonschlinkert) multimatch-2.1.0/test.js000066400000000000000000000225131262163620700152060ustar00rootroot00000000000000'use strict'; var expect = require('chai').expect; var mm = require('./'); describe('when an array of additive glob patterns is defined:', function () { it('should match on multiple patterns', function () { expect(mm(['unicorn', 'cake', 'rainbows'], ['*', '!cake'])).to.eql(['unicorn', 'rainbows']); expect(mm(['foo', 'bar', 'baz'], ['foo'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']); expect(mm(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']); }); it('should return an array of matches', function () { expect(mm(['foo', 'bar', 'baz'], ['f*'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['f*', 'bar'])).to.eql(['foo', 'bar']); }); it('should return matches in the order the patterns were defined', function () { expect(mm(['foo', 'bar', 'baz'], ['bar', 'f*'])).to.eql(['bar', 'foo']); expect(mm(['foo', 'bar', 'baz'], ['f*', '*z'])).to.eql(['foo', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['*z', 'f*'])).to.eql(['baz', 'foo']); }); }); describe('when additive string patterns are defined and matches are found:', function () { it('should return an array of matches', function () { expect(mm(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']); }); }); describe('when negation string patterns are defined', function () { it('should return an array with negations omitted', function () { expect(mm(['foo', 'bar', 'baz'], '!foo')).to.eql([]); }); }); describe('when an array of additive string patterns is defined and matches are found:', function () { it('should return an array of matches', function () { expect(mm(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']); }); it('should return an empty array when no matches are found', function () { expect(mm(['foo', 'bar', 'baz'], ['quux'])).to.eql([]); }); }); describe('when an array of negation glob patterns is defined', function () { it('should return an array with negations omitted', function () { expect(mm(['foo', 'bar', 'baz'], ['!*z'])).to.eql([]); }); it('should return an array with negations omitted', function () { expect(mm(['foo', 'bar', 'baz'], ['!*z', '!*a*'])).to.eql([]); }); it('should return an empty array when no matches are found', function () { expect(mm(['foo', 'bar', 'baz'], ['!*'])).to.eql([]); }); }); describe('when an array of filepaths is passed, and an array of negation glob patterns is defined', function () { var fixtures = ['vendor/js/foo.js', 'vendor/js/bar.js', 'vendor/js/baz.js']; it('should return an array with negations omitted', function () { expect(mm(fixtures, ['!**/*z.js'])).to.eql([]); }); it('should return an array with negations omitted', function () { expect(mm(fixtures, ['!**/*z.js', '**/foo.js'])).to.eql(['vendor/js/foo.js']); }); it('should return an array with negations omitted', function () { expect(mm(fixtures, ['!**/*z.js', '!**/*a*.js'])).to.eql([]); }); it('should return an empty array when no matches are found', function () { expect(mm(fixtures, ['!**/*.js'])).to.eql([]); }); }); describe('when an array of negation string patterns is defined', function () { it('should return an array with negations omitted', function () { expect(mm(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]); }); }); describe('when inclusion and negation patterns are defined', function () { it('should return an array of matches, sans negations', function () { expect(mm(['foo', 'bar', 'baz'], ['!*a*'])).to.eql([]); }); it('patterns should be order sensitive', function () { expect(mm(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); expect(mm(['foo', 'bar', 'baz'], ['*z', '!*a*'])).to.eql([]); expect(mm(['foo', 'foam', 'for', 'forum'], ['!*m', 'f*'])).to.eql(['foo', 'foam', 'for', 'forum']); expect(mm(['foo', 'foam', 'for', 'forum'], ['f*', '!*m'])).to.eql(['foo', 'for']); expect(mm(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['bar', '!foo', 'foo'])).to.eql(['bar', 'foo']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!foo', 'bar'])).to.eql(['bar']); }); it('should override negations and re-include explicitly defined patterns', function () { expect(mm(['foo', 'bar', 'baz'], ['!*'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['!*a*'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['bar', '!*a*'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['!*a*', 'bar'])).to.eql(['bar']); expect(mm(['foo', 'bar', 'baz'], ['!*a*', '*'])).to.eql(['foo', 'bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['!*a*', '*z'])).to.eql(['baz']); }); }); describe('misc', function () { it('misc', function () { expect(mm(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['*', '!foo', 'bar'])).to.eql(['bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['!foo', '*'])).to.eql(['foo', 'bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['*', '!foo', '!bar'])).to.eql(['baz']); expect(mm(['foo', 'bar', 'baz'], ['!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', '*'])).to.eql(['foo', 'bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['*', '!*{o,r}', 'foo'])).to.eql(['baz', 'foo']); expect(mm(['foo', 'bar', 'baz'], ['!*{o,r}', '*', 'foo'])).to.eql(['foo', 'bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!*{o,r}'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', 'foo'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['*', '!*{o,r}'])).to.eql(['baz']); expect(mm(['foo', 'bar', 'baz'], 'foo')).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['!foo'])).to.eql([]); expect(mm(['foo', 'bar', 'baz'], ['*', '!foo'])).to.eql(['bar', 'baz']); expect(mm(['foo', 'bar', 'baz'], ['foo', 'bar'])).to.eql(['foo', 'bar']); expect(mm(['foo', 'bar', 'baz'], ['foo', '!bar'])).to.eql(['foo']); expect(mm(['foo', 'bar', 'baz'], ['!foo', 'bar'])).to.eql(['bar']); expect(mm(['foo', 'bar', 'baz'], ['!foo', '!bar'])).to.eql([]); expect(mm(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['once', '!o*', 'once'])).to.eql(['once']); expect(mm(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['*', '!o*', 'once'])).to.eql(['foo', 'two', 'four', 'do', 'once']); }); }); /** * Tests from [globule](https://github.com/cowboy/node-globule) */ describe('globule', function () { it('Should return empty set if a required argument is missing or an empty set.', function () { expect(mm('', 'foo.js')).to.eql([]); expect(mm('*.js', '')).to.eql([]); expect(mm([], 'foo.js')).to.eql([]); expect(mm('*.js', [])).to.eql([]); expect(mm('', ['foo.js'])).to.eql([]); expect(mm(['*.js'], '')).to.eql([]); }); it('basic matching should match correctly', function () { expect(mm('foo.js', '*.js')).to.eql(['foo.js']); expect(mm(['foo.js'], '*.js')).to.eql(['foo.js']); expect(mm(['foo.js', 'bar.css'], '*.js')).to.eql(['foo.js']); expect(mm('foo.js', ['*.js', '*.css'])).to.eql(['foo.js']); expect(mm(['foo.js'], ['*.js', '*.css'])).to.eql(['foo.js']); expect(mm(['foo.js', 'bar.css'], ['*.js', '*.css'])).to.eql(['foo.js', 'bar.css']); }); describe('no matches:', function () { it('should fail to match', function () { expect(mm('foo.css', '*.js')).to.eql([]); expect(mm(['foo.css', 'bar.css'], '*.js')).to.eql([]); }); }); describe('unique:', function () { it('should return a uniqued set', function () { expect(mm(['foo.js', 'foo.js'], '*.js')).to.eql(['foo.js']); expect(mm(['foo.js', 'foo.js'], ['*.js', '*.*'])).to.eql(['foo.js']); }); }); describe('exclusion:', function () { it('solitary exclusion should match nothing', function () { expect(mm(['foo.js', 'bar.js'], ['!*.js'])).to.eql([]); }); it('exclusion should cancel match', function () { expect(mm(['foo.js', 'bar.js'], ['*.js', '!*.js'])).to.eql([]); }); it('partial exclusion should partially cancel match', function () { expect(mm(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js'])).to.eql(['bar.js', 'baz.js']); }); it('inclusion / exclusion order matters', function () { expect(mm(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!*.js', 'b*.js'])).to.eql(['bar.js', 'baz.js']); }); it('inclusion / exclusion order matters', function () { expect(mm(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js', '*.js'])).to.eql(['bar.js', 'baz.js', 'foo.js']); }); }); describe('options.matchBase:', function () { it('should matchBase (minimatch) when specified.', function () { expect(mm(['foo.js', 'bar', 'baz/xyz.js'], '*.js', {matchBase: true})).to.eql(['foo.js', 'baz/xyz.js']); }); it('should not matchBase (minimatch) by default.', function () { expect(mm(['foo.js', 'bar', 'baz/xyz.js'], '*.js')).to.eql(['foo.js']); }); }); });