Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Matches strings against configurable strings, globs, regular expressions, and/or functions
The anymatch npm package is a utility that allows you to match strings against a variety of patterns including strings, regexes, and functions. It is commonly used to test whether a given string matches any of a set of criteria, which is useful for tasks like filtering file paths or determining if an event should trigger a particular action.
String pattern matching
Match a string against a single glob pattern.
"foo.js".match(anymatch('*.js'))
Array of patterns matching
Match a string against an array of glob patterns.
anymatch(['*.js', '*.css'], 'foo.js')
Function as a custom matcher
Use a function as a custom matcher in the array of patterns.
anymatch([/\.js$/, (string) => string.includes('foo')], 'foo.js')
Negated patterns
Use negated patterns to exclude matches.
anymatch(['*.js', '!foo.js'], 'foo.js')
Partial application
Create a partially applied matcher function for reuse.
const isJsFile = anymatch('*.js');
isJsFile('foo.js');
Micromatch is a glob matching library that offers a variety of powerful features and optimizations. It is more extensive than anymatch, providing more fine-grained control over pattern matching and glob expansion.
Minimatch is a minimal matching utility that implements glob matching in JavaScript. It is the matcher used by npm itself and is similar to anymatch but with a simpler API and fewer features.
Multimatch extends minimatch to allow multiple patterns to be specified. It is similar to anymatch in that it can match against multiple patterns, but it is built on top of minimatch.
Picomatch is a small, fast, and powerful glob matcher with a simple API. It is similar to anymatch but focuses on performance and is suitable for runtime usage.
Javascript module to match a string against a regular expression, glob, string, or function that takes the string as an argument and returns a truthy or falsy value. The matcher can also be an array of any or all of these. Useful for allowing a very flexible user-defined config to define things like file paths.
npm install anymatch --save
var anymatch = require('anymatch');
var matchers = [
'path/to/file.js',
'path/anyjs/**/*.js',
/foo.js$/,
function (string) {
return string.indexOf('bar') !== -1 && string.length > 10
}
];
anymatch(matchers, 'path/to/file.js'); // true
anymatch(matchers, 'path/anyjs/baz.js'); // true
anymatch(matchers, 'path/to/foo.js'); // true
anymatch(matchers, 'path/to/bar.js'); // true
anymatch(matchers, 'bar.js'); // false
You can also use the checker
method to get a function that has already been
bound to your matchers.
var matcher = anymatch.matcher(matchers);
matcher('path/to/file.js'); // true
FAQs
Matches strings against configurable strings, globs, regular expressions, and/or functions
The npm package anymatch receives a total of 42,711,348 weekly downloads. As such, anymatch popularity was classified as popular.
We found that anymatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.