diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/matcher | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) | |
download | wallet-core-363723fc84f7b8477592e0105aeb331ec9a017af.tar.xz |
node_modules
Diffstat (limited to 'node_modules/matcher')
-rw-r--r-- | node_modules/matcher/index.js | 51 | ||||
-rw-r--r-- | node_modules/matcher/package.json | 9 | ||||
-rw-r--r-- | node_modules/matcher/readme.md | 9 |
3 files changed, 37 insertions, 32 deletions
diff --git a/node_modules/matcher/index.js b/node_modules/matcher/index.js index 796e7c8d0..947d8cf4f 100644 --- a/node_modules/matcher/index.js +++ b/node_modules/matcher/index.js @@ -1,15 +1,16 @@ 'use strict'; -var escapeStringRegexp = require('escape-string-regexp'); -var reCache = {}; +const escapeStringRegexp = require('escape-string-regexp'); + +const reCache = new Map(); function makeRe(pattern, shouldNegate) { - var cacheKey = pattern + shouldNegate; + const cacheKey = pattern + shouldNegate; - if (reCache[cacheKey]) { - return reCache[cacheKey]; + if (reCache.has(cacheKey)) { + return reCache.get(cacheKey); } - var negated = false; + let negated = false; if (pattern[0] === '!') { negated = true; @@ -19,54 +20,48 @@ function makeRe(pattern, shouldNegate) { pattern = escapeStringRegexp(pattern).replace(/\\\*/g, '.*'); if (negated && shouldNegate) { - pattern = '(?!' + pattern + ')'; + pattern = `(?!${pattern})`; } - var re = new RegExp('^' + pattern + '$', 'i'); - + const re = new RegExp(`^${pattern}$`, 'i'); re.negated = negated; - - reCache[cacheKey] = re; + reCache.set(cacheKey, re); return re; } -module.exports = function (inputs, patterns) { +module.exports = (inputs, patterns) => { if (!(Array.isArray(inputs) && Array.isArray(patterns))) { - throw new TypeError('Expected two arrays, got ' + typeof inputs + ' ' + typeof patterns); + throw new TypeError(`Expected two arrays, got ${typeof inputs} ${typeof patterns}`); } if (patterns.length === 0) { return inputs; } - var firstNegated = patterns[0][0] === '!'; + const firstNegated = patterns[0][0] === '!'; - patterns = patterns.map(function (x) { - return makeRe(x, false); - }); + patterns = patterns.map(x => makeRe(x, false)); - var ret = []; + const ret = []; - for (var i = 0; i < inputs.length; i++) { - // if first pattern is negated we include - // everything to match user expectation - var matches = firstNegated; + for (const input of inputs) { + // If first pattern is negated we include everything to match user expectation + let matches = firstNegated; - for (var j = 0; j < patterns.length; j++) { - if (patterns[j].test(inputs[i])) { + // 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; } } if (matches) { - ret.push(inputs[i]); + ret.push(input); } } return ret; }; -module.exports.isMatch = function (input, pattern) { - return makeRe(pattern, true).test(input); -}; +module.exports.isMatch = (input, pattern) => makeRe(pattern, true).test(input); diff --git a/node_modules/matcher/package.json b/node_modules/matcher/package.json index cc1523794..b5d97680b 100644 --- a/node_modules/matcher/package.json +++ b/node_modules/matcher/package.json @@ -1,6 +1,6 @@ { "name": "matcher", - "version": "0.1.2", + "version": "1.0.0", "description": "Simple wildcard matching", "license": "MIT", "repository": "sindresorhus/matcher", @@ -10,10 +10,11 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { - "test": "xo && ava" + "test": "xo && ava", + "bench": "matcha bench.js" }, "files": [ "index.js" @@ -31,6 +32,7 @@ "string", "filter", "glob", + "globber", "globbing", "minimatch" ], @@ -39,6 +41,7 @@ }, "devDependencies": { "ava": "*", + "matcha": "^0.7.0", "xo": "*" } } diff --git a/node_modules/matcher/readme.md b/node_modules/matcher/readme.md index 42488b5a7..6716eecbf 100644 --- a/node_modules/matcher/readme.md +++ b/node_modules/matcher/readme.md @@ -68,6 +68,13 @@ Type: `string` Case-insensitive. Use `*` to match zero or more characters. A pattern starting with `!` will be negated. +## Benchmark + +``` +$ npm run bench +``` + + ## Related - [multimatch](https://github.com/sindresorhus/multimatch) - Extends `minimatch.match()` with support for multiple patterns @@ -75,4 +82,4 @@ Case-insensitive. Use `*` to match zero or more characters. A pattern starting w ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +MIT © [Sindre Sorhus](https://sindresorhus.com) |