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.
multimatch
Advanced tools
The multimatch npm package allows for matching file paths against specified glob patterns. It is a wrapper around the 'minimatch' library, providing the ability to use multiple patterns at once for more complex matching scenarios. This can be particularly useful in build processes, file selection for operations like copying, deleting, or applying specific processing, and in any context where a list of files needs to be filtered based on flexible criteria.
Basic glob matching
This feature demonstrates basic usage of multimatch to filter an array of file paths based on a simple glob pattern. It's useful for selecting files of a specific type.
const multimatch = require('multimatch');
const paths = ['index.html', 'styles/main.css', 'scripts/app.js'];
const matched = multimatch(paths, '*.html');
console.log(matched); // ['index.html']
Multiple pattern matching
This feature shows how to use multimatch with multiple patterns to filter file paths. It's particularly useful when you need to select files that match any of several criteria.
const multimatch = require('multimatch');
const paths = ['index.html', 'styles/main.css', 'scripts/app.js', 'images/logo.png'];
const matched = multimatch(paths, ['*.css', '*.js']);
console.log(matched); // ['styles/main.css', 'scripts/app.js']
Exclusion patterns
This feature illustrates the use of exclusion patterns to filter out files that match a certain pattern. It's useful for excluding specific files or directories from a broader selection.
const multimatch = require('multimatch');
const paths = ['index.html', 'styles/main.css', 'scripts/app.js', 'test/app.test.js'];
const matched = multimatch(paths, ['*.js', '!test/*.js']);
console.log(matched); // ['scripts/app.js']
The 'glob' package provides similar functionality for matching files using glob patterns. Unlike multimatch, glob interacts directly with the filesystem to filter files based on patterns. This makes it more suited for operations that require reading from or writing to the disk, but less convenient for filtering an existing list of file paths.
The 'minimatch' package is the core matching library behind multimatch. It offers the fundamental functionality for pattern matching but does so on a one-pattern-at-a-time basis. Multimatch extends this by allowing multiple patterns to be used simultaneously, making it more convenient for complex matching scenarios.
Adds multiple patterns support to
minimatch.match()
Minimatch:
minimatch.match(['unicorn', 'cake', 'rainbows'], '*corn');
Multimatch:
multimatch(['unicorn', 'cake', 'rainbows'], ['*corn', 'rain*']);
Install with npm
npm install --save multimatch
var multimatch = require('multimatch');
multimatch(['unicorn', 'cake', 'rainbows'], ['!cake', '*corn']));
//=> ['unicorn', 'rainbows']
Patterns are additive while negations (eg ['foo', '!bar']
) are based on the current set. Exception is if the first pattern is negation, then it will get the full set, so to match user expectation (eg. ['!foo']
will match everything except foo
). Order matters.
See the tests for more usage examples and expected matches.
Same as multimatch.match()
except for pattern
also accepting an array.
MIT © Sindre Sorhus
FAQs
Extends `minimatch.match()` with support for multiple patterns
The npm package multimatch receives a total of 1,872,927 weekly downloads. As such, multimatch popularity was classified as popular.
We found that multimatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.