pax_global_header00006660000000000000000000000064137411001500014502gustar00rootroot0000000000000052 comment=5a973fad8a5d8d794d98a324ae3598f8c707c496 multimatch-5.0.0/000077500000000000000000000000001374110015000136535ustar00rootroot00000000000000multimatch-5.0.0/.editorconfig000066400000000000000000000002571374110015000163340ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 multimatch-5.0.0/.gitattributes000066400000000000000000000000231374110015000165410ustar00rootroot00000000000000* text=auto eol=lf multimatch-5.0.0/.github/000077500000000000000000000000001374110015000152135ustar00rootroot00000000000000multimatch-5.0.0/.github/funding.yml000066400000000000000000000001641374110015000173710ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus custom: https://sindresorhus.com/donate tidelift: npm/multimatch multimatch-5.0.0/.github/security.md000066400000000000000000000002631374110015000174050ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. multimatch-5.0.0/.gitignore000066400000000000000000000000271374110015000156420ustar00rootroot00000000000000node_modules yarn.lock multimatch-5.0.0/.npmrc000066400000000000000000000000231374110015000147660ustar00rootroot00000000000000package-lock=false multimatch-5.0.0/.travis.yml000066400000000000000000000000661374110015000157660ustar00rootroot00000000000000language: node_js node_js: - '14' - '12' - '10' multimatch-5.0.0/index.d.ts000066400000000000000000000014721374110015000155600ustar00rootroot00000000000000import {IOptions} from 'minimatch'; declare namespace multimatch { type Options = Readonly; } /** Extends [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) with support for multiple patterns. @param paths - Paths to match against. @param patterns - Globbing patterns to use. For example: `['*', '!cake']`. See supported [`minimatch` patterns](https://github.com/isaacs/minimatch#usage). @returns The matching paths in the order of input paths. @example ``` import multimatch = require('multimatch'); multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']); //=> ['unicorn', 'rainbows'] ``` */ declare function multimatch( paths: string | readonly string[], patterns: string | readonly string[], options?: multimatch.Options ): string[]; export = multimatch; multimatch-5.0.0/index.js000066400000000000000000000012161374110015000153200ustar00rootroot00000000000000'use strict'; const minimatch = require('minimatch'); const arrayUnion = require('array-union'); const arrayDiffer = require('array-differ'); const arrify = require('arrify'); module.exports = (list, patterns, options = {}) => { list = arrify(list); patterns = arrify(patterns); if (list.length === 0 || patterns.length === 0) { return []; } let result = []; for (const item of list) { for (let pattern of patterns) { let process = arrayUnion; if (pattern[0] === '!') { pattern = pattern.slice(1); process = arrayDiffer; } result = process(result, minimatch.match([item], pattern, options)); } } return result; }; multimatch-5.0.0/index.test-d.ts000066400000000000000000000005141374110015000165310ustar00rootroot00000000000000import multimatch = require('.'); // eslint-disable-next-line @typescript-eslint/no-unused-vars const options: multimatch.Options = {}; multimatch(['unicorn', 'cake', 'rainbows'], '!cake'); multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']); multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake'], { debug: true }); multimatch-5.0.0/license000066400000000000000000000021351374110015000152210ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) 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-5.0.0/package.json000066400000000000000000000015641374110015000161470ustar00rootroot00000000000000{ "name": "multimatch", "version": "5.0.0", "description": "Extends `minimatch.match()` with support for multiple patterns", "license": "MIT", "repository": "sindresorhus/multimatch", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "expand", "find", "glob", "globbing", "globs", "match", "matcher", "minimatch", "pattern", "patterns", "wildcard" ], "dependencies": { "@types/minimatch": "^3.0.3", "array-differ": "^3.0.0", "array-union": "^2.1.0", "arrify": "^2.0.1", "minimatch": "^3.0.4" }, "devDependencies": { "ava": "^2.4.0", "tsd": "^0.13.1", "xo": "^0.33.1" } } multimatch-5.0.0/readme.md000066400000000000000000000047651374110015000154460ustar00rootroot00000000000000# multimatch [![Build Status](https://travis-ci.com/sindresorhus/multimatch.svg?branch=master)](https://travis-ci.com/github/sindresorhus/multimatch) > Extends [`minimatch.match()`](https://github.com/isaacs/minimatch#minimatchmatchlist-pattern-options) with support for multiple patterns ## Install ``` $ npm install multimatch ``` ## Usage ```js const multimatch = require('multimatch'); multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']); //=> ['unicorn', 'rainbows'] ``` See the [tests](https://github.com/sindresorhus/multimatch/tree/master/test) for more usage examples and expected matches. ## API ### multimatch(paths, patterns, options?) Returns an array of matching paths in the order of input paths. #### paths Type: `string | string[]` Paths to match against. #### patterns Type: `string | string[]` Globbing patterns to use. For example: `['*', '!cake']`. See supported [`minimatch` patterns](https://github.com/isaacs/minimatch#usage). - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) #### options Type: `object` See the [`minimatch` options](https://github.com/isaacs/minimatch#options). ## 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 - [globby](https://github.com/sindresorhus/globby) - Match against the filesystem instead of a list - [matcher](https://github.com/sindresorhus/matcher) - Simple wildcard matching ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
multimatch-5.0.0/test/000077500000000000000000000000001374110015000146325ustar00rootroot00000000000000multimatch-5.0.0/test/globule.js000066400000000000000000000043761374110015000166330ustar00rootroot00000000000000// Tests from [globule](https://github.com/cowboy/node-globule) import test from 'ava'; import multimatch from '..'; test('Should return empty set if a required argument is missing or an empty set.', t => { t.deepEqual(multimatch('', 'foo.js'), []); t.deepEqual(multimatch('*.js', ''), []); t.deepEqual(multimatch([], 'foo.js'), []); t.deepEqual(multimatch('*.js', []), []); t.deepEqual(multimatch('', ['foo.js']), []); t.deepEqual(multimatch(['*.js'], ''), []); }); test('basic matching should match correctly', t => { t.deepEqual(multimatch('foo.js', '*.js'), ['foo.js']); t.deepEqual(multimatch(['foo.js'], '*.js'), ['foo.js']); t.deepEqual(multimatch(['foo.js', 'bar.css'], '*.js'), ['foo.js']); t.deepEqual(multimatch('foo.js', ['*.js', '*.css']), ['foo.js']); t.deepEqual(multimatch(['foo.js'], ['*.js', '*.css']), ['foo.js']); t.deepEqual(multimatch(['foo.js', 'bar.css'], ['*.js', '*.css']), ['foo.js', 'bar.css']); }); test('should fail to match', t => { t.deepEqual(multimatch('foo.css', '*.js'), []); t.deepEqual(multimatch(['foo.css', 'bar.css'], '*.js'), []); }); test('should return a uniqued set', t => { t.deepEqual(multimatch(['foo.js', 'foo.js'], '*.js'), ['foo.js']); t.deepEqual(multimatch(['foo.js', 'foo.js'], ['*.js', '*.*']), ['foo.js']); }); test('solitary exclusion should match nothing', t => { t.deepEqual(multimatch(['foo.js', 'bar.js'], ['!*.js']), []); }); test('exclusion should cancel match', t => { t.deepEqual(multimatch(['foo.js', 'bar.js'], ['*.js', '!*.js']), []); }); test('partial exclusion should partially cancel match', t => { t.deepEqual(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js']), ['bar.js', 'baz.js']); }); test('inclusion / exclusion order matters', t => { t.deepEqual(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!*.js', 'b*.js']), ['bar.js', 'baz.js']); t.deepEqual(multimatch(['foo.js', 'bar.js', 'baz.js'], ['*.js', '!f*.js', '*.js']), ['foo.js', 'bar.js', 'baz.js']); }); test('should matchBase (minimatch) when specified.', t => { t.deepEqual(multimatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js', {matchBase: true}), ['foo.js', 'baz/xyz.js']); }); test('should not matchBase (minimatch) by default.', t => { t.deepEqual(multimatch(['foo.js', 'bar', 'baz/xyz.js'], '*.js'), ['foo.js']); }); multimatch-5.0.0/test/test.js000066400000000000000000000132271374110015000161540ustar00rootroot00000000000000import test from 'ava'; import multimatch from '..'; const fixtures = ['vendor/js/foo.js', 'vendor/js/bar.js', 'vendor/js/baz.js']; test('match on multiple patterns', t => { t.deepEqual(multimatch(['unicorn', 'cake', 'rainbows'], ['*', '!cake']), ['unicorn', 'rainbows']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar']), ['foo', 'bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar']), ['bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo']), ['foo']); }); test('return an array of matches', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], 'foo'), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['f*']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['f*', 'bar']), ['foo', 'bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar']), ['foo', 'bar']); }); test('return matches in the order the list were defined', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['bar', 'f*']), ['foo', 'bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['f*', '*z']), ['foo', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*z', 'f*']), ['foo', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*z', '*r', 'f*']), ['foo', 'bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*a*', '!f*']), ['bar', 'baz']); }); test('return an array with negations omitted', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], '!foo'), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*z']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*z', '!*a*']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*']), []); t.deepEqual(multimatch(fixtures, ['!**/*z.js']), []); t.deepEqual(multimatch(fixtures, ['!**/*z.js', '**/foo.js']), ['vendor/js/foo.js']); t.deepEqual(multimatch(fixtures, ['!**/*z.js', '!**/*a*.js']), []); }); test('return an empty array when no matches are found', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['quux']), []); t.deepEqual(multimatch(fixtures, ['!**/*.js']), []); }); test('patterns be order sensitive', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z']), ['baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*z', '!*a*']), []); t.deepEqual(multimatch(['foo', 'foam', 'for', 'forum'], ['!*m', 'f*']), ['foo', 'foam', 'for', 'forum']); t.deepEqual(multimatch(['foo', 'foam', 'for', 'forum'], ['f*', '!*m']), ['foo', 'for']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar']), ['bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['bar', '!foo', 'foo']), ['foo', 'bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!foo', 'bar']), ['bar']); }); test('override negations and re-include explicitly defined patterns', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['bar', '!*a*']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', 'bar']), ['bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*']), ['foo', 'bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*a*', '*z']), ['baz']); }); test('misc', t => { t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo']), ['bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo', 'bar']), ['bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo']), ['bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '*']), ['foo', 'bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo', '!bar']), ['baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*']), ['foo', 'bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}']), ['baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', '*']), ['foo', 'bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}', 'foo']), ['foo', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', '*', 'foo']), ['foo', 'bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!*{o,r}', 'foo']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!*{o,r}', 'foo']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!*{o,r}']), ['baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], 'foo'), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo']), []); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['*', '!foo']), ['bar', 'baz']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', 'bar']), ['foo', 'bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['foo', '!bar']), ['foo']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', 'bar']), ['bar']); t.deepEqual(multimatch(['foo', 'bar', 'baz'], ['!foo', '!bar']), []); t.deepEqual(multimatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['once', '!o*', 'once']), ['once']); t.deepEqual(multimatch(['foo', 'one', 'two', 'four', 'do', 'once', 'only'], ['*', '!o*', 'once']), ['foo', 'two', 'four', 'do', 'once']); });