@pnpm/matcher
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -1,1 +0,3 @@ | ||
export default function matcher(patterns: string[] | string): (input: string) => boolean; | ||
declare type Matcher = (input: string) => boolean; | ||
export default function matcher(patterns: string[] | string): Matcher; | ||
export {}; |
@@ -9,9 +9,33 @@ "use strict"; | ||
if (typeof patterns === 'string') | ||
return matcherFromPattern(patterns); | ||
return matcherWhenOnlyOnePattern(patterns); | ||
switch (patterns.length) { | ||
case 0: return () => false; | ||
case 1: return matcherFromPattern(patterns[0]); | ||
case 1: return matcherWhenOnlyOnePattern(patterns[0]); | ||
} | ||
const matchArr = patterns.map(matcherFromPattern); | ||
return (input) => matchArr.some((match) => match(input)); | ||
const matchArr = []; | ||
let hasIgnore = false; | ||
for (const pattern of patterns) { | ||
if (isIgnorePattern(pattern)) { | ||
hasIgnore = true; | ||
matchArr.push({ ignore: true, match: matcherFromPattern(pattern.substring(1)) }); | ||
} | ||
else { | ||
matchArr.push({ ignore: false, match: matcherFromPattern(pattern) }); | ||
} | ||
} | ||
if (!hasIgnore) { | ||
return (input) => matchArr.some(({ match }) => match(input)); | ||
} | ||
return (input) => { | ||
let isMatched = false; | ||
for (const { ignore, match } of matchArr) { | ||
if (ignore) { | ||
isMatched = !match(input); | ||
} | ||
else if (!isMatched && match(input)) { | ||
isMatched = true; | ||
} | ||
} | ||
return isMatched; | ||
}; | ||
} | ||
@@ -30,2 +54,10 @@ exports.default = matcher; | ||
} | ||
function isIgnorePattern(pattern) { | ||
return pattern.startsWith('!'); | ||
} | ||
function matcherWhenOnlyOnePattern(pattern) { | ||
return isIgnorePattern(pattern) | ||
? () => false | ||
: matcherFromPattern(pattern); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/matcher", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "A simple pattern matcher for pnpm", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"engines": { | ||
"node": ">=14.19" | ||
"node": ">=14.6" | ||
}, | ||
@@ -33,3 +33,3 @@ "files": [ | ||
"devDependencies": { | ||
"@pnpm/matcher": "3.0.0" | ||
"@pnpm/matcher": "3.1.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
6478
63
0