What is matcher-collection?
The matcher-collection npm package is a utility that allows you to efficiently test if a value matches any of a collection of patterns. It is often used to filter or find items in a list that match certain criteria.
What are matcher-collection's main functionalities?
Matching strings against patterns
This feature allows you to create a collection of string patterns and then test if a given string matches any of those patterns. The patterns can include wildcards.
"use strict";
const MatcherCollection = require('matcher-collection');
let matchers = new MatcherCollection(['foo*', 'bar']);
console.log(matchers.match('foobar')); // true
console.log(matchers.match('barbaz')); // true
console.log(matchers.match('qux')); // false
Matching with regular expressions
Matcher-collection can also handle regular expressions, allowing for more complex matching scenarios.
"use strict";
const MatcherCollection = require('matcher-collection');
let matchers = new MatcherCollection([/foo/, 'bar']);
console.log(matchers.match('foobar')); // true
console.log(matchers.match('barbaz')); // true
console.log(matchers.match('quxfoo')); // true
console.log(matchers.match('qux')); // false
Other packages similar to matcher-collection
micromatch
Micromatch is a highly optimized wildcard and glob matching library. It is more feature-rich than matcher-collection, supporting a broader range of pattern matching options, including advanced globbing.
anymatch
Anymatch is a package that allows you to match strings against a mixture of strings, regexes, and functions. It provides a similar functionality to matcher-collection but also allows for matching using custom test functions.
multimatch
Multimatch extends the capabilities of micromatch by allowing multiple patterns to be matched against multiple strings. It is similar to matcher-collection in that it deals with collections of patterns, but it is built on top of micromatch for more powerful pattern matching.
MatcherCollection
Minimatch but for collections of minimatcher matchers.
Install
yarn add matcher-collection
Examples
const MatcherCollection = require('matcher-collection')
const m = new MatcherCollection([
'tests/',
'**/*.js',
]);
m.match('tests/foo.js')
m.match('foo.js')
m.mayContain('tests')
m.mayContain('foo')