diff options
Diffstat (limited to 'node_modules/matcher')
-rw-r--r-- | node_modules/matcher/index.js | 36 | ||||
-rw-r--r-- | node_modules/matcher/license | 20 | ||||
-rw-r--r-- | node_modules/matcher/package.json | 90 | ||||
-rw-r--r-- | node_modules/matcher/readme.md | 29 |
4 files changed, 92 insertions, 83 deletions
diff --git a/node_modules/matcher/index.js b/node_modules/matcher/index.js index 947d8cf4f..33e4e1532 100644 --- a/node_modules/matcher/index.js +++ b/node_modules/matcher/index.js @@ -3,34 +3,33 @@ const escapeStringRegexp = require('escape-string-regexp'); const reCache = new Map(); -function makeRe(pattern, shouldNegate) { - const cacheKey = pattern + shouldNegate; +function makeRe(pattern, options) { + const opts = Object.assign({ + caseSensitive: false + }, options); + + const cacheKey = pattern + JSON.stringify(opts); if (reCache.has(cacheKey)) { return reCache.get(cacheKey); } - let negated = false; + const negated = pattern[0] === '!'; - if (pattern[0] === '!') { - negated = true; + if (negated) { pattern = pattern.slice(1); } pattern = escapeStringRegexp(pattern).replace(/\\\*/g, '.*'); - if (negated && shouldNegate) { - pattern = `(?!${pattern})`; - } - - const re = new RegExp(`^${pattern}$`, 'i'); + const re = new RegExp(`^${pattern}$`, opts.caseSensitive ? '' : 'i'); re.negated = negated; reCache.set(cacheKey, re); return re; } -module.exports = (inputs, patterns) => { +module.exports = (inputs, patterns, options) => { if (!(Array.isArray(inputs) && Array.isArray(patterns))) { throw new TypeError(`Expected two arrays, got ${typeof inputs} ${typeof patterns}`); } @@ -41,7 +40,7 @@ module.exports = (inputs, patterns) => { const firstNegated = patterns[0][0] === '!'; - patterns = patterns.map(x => makeRe(x, false)); + patterns = patterns.map(x => makeRe(x, options)); const ret = []; @@ -49,10 +48,9 @@ module.exports = (inputs, patterns) => { // If first pattern is negated we include everything to match user expectation let matches = firstNegated; - // TODO: Figure out why tests fail when I use a for-of loop here - for (let j = 0; j < patterns.length; j++) { - if (patterns[j].test(input)) { - matches = !patterns[j].negated; + for (const pattern of patterns) { + if (pattern.test(input)) { + matches = !pattern.negated; } } @@ -64,4 +62,8 @@ module.exports = (inputs, patterns) => { return ret; }; -module.exports.isMatch = (input, pattern) => makeRe(pattern, true).test(input); +module.exports.isMatch = (input, pattern, options) => { + const re = makeRe(pattern, options); + const matches = re.test(input); + return re.negated ? !matches : matches; +}; diff --git a/node_modules/matcher/license b/node_modules/matcher/license index 654d0bfe9..e7af2f771 100644 --- a/node_modules/matcher/license +++ b/node_modules/matcher/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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: +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 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. +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. diff --git a/node_modules/matcher/package.json b/node_modules/matcher/package.json index b5d97680b..7fe40a112 100644 --- a/node_modules/matcher/package.json +++ b/node_modules/matcher/package.json @@ -1,47 +1,47 @@ { - "name": "matcher", - "version": "1.0.0", - "description": "Simple wildcard matching", - "license": "MIT", - "repository": "sindresorhus/matcher", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava", - "bench": "matcha bench.js" - }, - "files": [ - "index.js" - ], - "keywords": [ - "matcher", - "matching", - "match", - "regex", - "regexp", - "regular", - "expression", - "wildcard", - "pattern", - "string", - "filter", - "glob", - "globber", - "globbing", - "minimatch" - ], - "dependencies": { - "escape-string-regexp": "^1.0.4" - }, - "devDependencies": { - "ava": "*", - "matcha": "^0.7.0", - "xo": "*" - } + "name": "matcher", + "version": "1.1.1", + "description": "Simple wildcard matching", + "license": "MIT", + "repository": "sindresorhus/matcher", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava", + "bench": "matcha bench.js" + }, + "files": [ + "index.js" + ], + "keywords": [ + "matcher", + "matching", + "match", + "regex", + "regexp", + "regular", + "expression", + "wildcard", + "pattern", + "string", + "filter", + "glob", + "globber", + "globbing", + "minimatch" + ], + "dependencies": { + "escape-string-regexp": "^1.0.4" + }, + "devDependencies": { + "ava": "*", + "matcha": "^0.7.0", + "xo": "*" + } } diff --git a/node_modules/matcher/readme.md b/node_modules/matcher/readme.md index 6716eecbf..f395cfb71 100644 --- a/node_modules/matcher/readme.md +++ b/node_modules/matcher/readme.md @@ -8,7 +8,7 @@ Useful when you want to accept loose string input and regexes/globs are too conv ## Install ``` -$ npm install --save matcher +$ npm install matcher ``` @@ -40,18 +40,24 @@ matcher.isMatch('foo bar baz', 'foo b* b*'); matcher.isMatch('unicorn', 'uni\\*'); //=> false + +matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true}); +//=> true + +matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true}); +//=> false ``` ## API -### matcher(inputs, patterns) +### matcher(inputs, patterns, [options]) Accepts an array of `input`'s and `pattern`'s. -Returns an array of of `inputs` filtered based on the `patterns`. +Returns an array of `inputs` filtered based on the `patterns`. -### matcher.isMatch(input, pattern) +### matcher.isMatch(input, pattern, [options]) Returns a boolean of whether the `input` matches the `pattern`. @@ -61,11 +67,24 @@ Type: `string` String to match. +#### options + +Type: `Object` + +##### caseSensitive + +Type: `boolean`<br> +Default: `false` + +Treat uppercase and lowercase characters as being the same. + +Ensure you use this correctly. For example, files and directories should be matched case-insensitively, while most often, object keys should be matched case-sensitively. + #### pattern Type: `string` -Case-insensitive. Use `*` to match zero or more characters. A pattern starting with `!` will be negated. +Use `*` to match zero or more characters. A pattern starting with `!` will be negated. ## Benchmark |