anymatch
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -5,7 +5,15 @@ // type | ||
type AnymatchFn = (string) => boolean; | ||
type AnymatchFn = (testString: string) => boolean; | ||
type AnymatchPattern = string|RegExp|AnymatchFn; | ||
type AnymatchMatcher = AnymatchPattern|Array<AnymatchPattern> | ||
declare function anymatch(matchers: AnymatchMatcher, testString: string|Array, returnIndex?: boolean): boolean; | ||
declare function anymatch(matchers: AnymatchMatcher): (testString: string|Array, returnIndex?: boolean) => number; | ||
export = anymatch; | ||
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[] | ||
type AnymatchTester = { | ||
(testString: string|any[], returnIndex: true): number; | ||
(testString: string|any[]): boolean; | ||
} | ||
declare const anymatch: { | ||
(matchers: AnymatchMatcher): AnymatchTester; | ||
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true): number; | ||
(matchers: AnymatchMatcher, testString: string|any[]): boolean; | ||
} | ||
export = anymatch |
31
index.js
@@ -7,9 +7,6 @@ 'use strict'; | ||
/** | ||
* @typedef {(...args) => boolean} BooleanFn | ||
* @typedef {(string) => boolean} StrBoolFn | ||
* @typedef {BooleanFn|StrBoolFn} AnymatchFn | ||
* @typedef {(testString: string) => boolean} AnymatchFn | ||
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern | ||
* @typedef {AnymatchPattern|Array<AnymatchPattern>} AnymatchMatcher | ||
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher | ||
*/ | ||
const BANG = '!'; | ||
@@ -41,2 +38,3 @@ const arrify = (item) => Array.isArray(item) ? item : [item]; | ||
* @param {Boolean} returnIndex | ||
* @returns {boolean|number} | ||
*/ | ||
@@ -46,20 +44,13 @@ const matchPatterns = (patterns, negatedGlobs, path, returnIndex) => { | ||
const upath = normalizePath(additionalArgs ? path[0] : path); | ||
if (negatedGlobs.length > 0) { | ||
for (let index = 0; index < negatedGlobs.length; index++) { | ||
const nglob = negatedGlobs[index]; | ||
if (nglob(upath)) { | ||
return returnIndex ? -1 : false; | ||
} | ||
for (let index = 0; index < negatedGlobs.length; index++) { | ||
const nglob = negatedGlobs[index]; | ||
if (nglob(upath)) { | ||
return returnIndex ? -1 : false; | ||
} | ||
} | ||
const args = additionalArgs && [upath].concat(path.slice(1)); | ||
for (let index = 0; index < patterns.length; index++) { | ||
const pattern = patterns[index]; | ||
if (additionalArgs) { | ||
if (pattern(...path)) { | ||
return returnIndex ? index : true; | ||
} | ||
} else { | ||
if (pattern(upath)) { | ||
return returnIndex ? index : true; | ||
} | ||
if (additionalArgs ? pattern(...args) : pattern(upath)) { | ||
return returnIndex ? index : true; | ||
} | ||
@@ -74,3 +65,3 @@ } | ||
* @param {Array|string} testString | ||
* @param {Boolean=} returnIndex | ||
* @param {boolean=} returnIndex | ||
* @returns {boolean|number|Function} | ||
@@ -77,0 +68,0 @@ */ |
{ | ||
"name": "anymatch", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions", | ||
@@ -42,8 +42,8 @@ "files": [ | ||
"normalize-path": "^3.0.0", | ||
"picomatch": "^2.0.3" | ||
"picomatch": "^2.0.4" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^6.1.2", | ||
"nyc": "^13.3.0" | ||
"mocha": "^6.1.3", | ||
"nyc": "^14.0.0" | ||
} | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
8829
96
Updatedpicomatch@^2.0.4