Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

matcher

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

matcher - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

28

index.js

@@ -6,5 +6,9 @@ 'use strict';

function makeRe(pattern, shouldNegate) {
const cacheKey = pattern + shouldNegate;
function makeRe(pattern, shouldNegate, options) {
const opts = Object.assign({
caseSensitive: false
}, options);
const cacheKey = pattern + shouldNegate + JSON.stringify(opts);
if (reCache.has(cacheKey)) {

@@ -14,6 +18,5 @@ return reCache.get(cacheKey);

let negated = false;
const negated = pattern[0] === '!';
if (pattern[0] === '!') {
negated = true;
if (negated) {
pattern = pattern.slice(1);

@@ -28,3 +31,3 @@ }

const re = new RegExp(`^${pattern}$`, 'i');
const re = new RegExp(`^${pattern}$`, opts.caseSensitive ? '' : 'i');
re.negated = negated;

@@ -36,3 +39,3 @@ reCache.set(cacheKey, re);

module.exports = (inputs, patterns) => {
module.exports = (inputs, patterns, options) => {
if (!(Array.isArray(inputs) && Array.isArray(patterns))) {

@@ -48,3 +51,3 @@ throw new TypeError(`Expected two arrays, got ${typeof inputs} ${typeof patterns}`);

patterns = patterns.map(x => makeRe(x, false));
patterns = patterns.map(x => makeRe(x, false, options));

@@ -57,6 +60,5 @@ const ret = [];

// 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;
}

@@ -73,2 +75,2 @@ }

module.exports.isMatch = (input, pattern) => makeRe(pattern, true).test(input);
module.exports.isMatch = (input, pattern, options) => makeRe(pattern, true, options).test(input);
{
"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.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": "*"
}
}

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

```
$ npm install --save matcher
$ npm install matcher
```

@@ -44,2 +44,8 @@

//=> false
matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true});
//=> true
matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true});
//=> false
```

@@ -50,9 +56,9 @@

### 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])

@@ -67,2 +73,15 @@ Returns a boolean of whether the `input` matches the `pattern`.

#### 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

@@ -72,3 +91,3 @@

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.

@@ -75,0 +94,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc