Socket
Socket
Sign inDemoInstall

matcher

Package Overview
Dependencies
1
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 1.0.0

51

index.js
'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;

@@ -22,17 +23,15 @@ if (pattern[0] === '!') {

if (negated && shouldNegate) {
pattern = '(?!' + pattern + ')';
pattern = `(?!${pattern})`;
}
var re = new RegExp('^' + pattern + '$', 'i');
const re = new RegExp(`^${pattern}$`, 'i');
re.negated = negated;
reCache.set(cacheKey, re);
reCache[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}`);
}

@@ -44,17 +43,15 @@

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;

@@ -65,3 +62,3 @@ }

if (matches) {
ret.push(inputs[i]);
ret.push(input);
}

@@ -73,4 +70,2 @@ }

module.exports.isMatch = function (input, pattern) {
return makeRe(pattern, true).test(input);
};
module.exports.isMatch = (input, pattern) => makeRe(pattern, true).test(input);
{
"name": "matcher",
"version": "0.1.2",
"version": "1.0.0",
"description": "Simple wildcard matching",

@@ -13,6 +13,7 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava",
"bench": "matcha bench.js"
},

@@ -35,2 +36,3 @@ "files": [

"glob",
"globber",
"globbing",

@@ -44,4 +46,5 @@ "minimatch"

"ava": "*",
"matcha": "^0.7.0",
"xo": "*"
}
}

@@ -71,2 +71,9 @@ # matcher [![Build Status](https://travis-ci.org/sindresorhus/matcher.svg?branch=master)](https://travis-ci.org/sindresorhus/matcher)

## Benchmark
```
$ npm run bench
```
## Related

@@ -79,2 +86,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc