What is wildcard-match?
The wildcard-match npm package is used for matching strings against wildcard patterns. It is useful for tasks such as filtering file paths, validating input strings, and more.
What are wildcard-match's main functionalities?
Basic Wildcard Matching
This feature allows you to check if a string matches a given wildcard pattern. In this example, 'foobar' matches the pattern 'foo*'.
const wildcard = require('wildcard-match');
const isMatch = wildcard('foo*')('foobar');
console.log(isMatch); // true
Case-Insensitive Matching
This feature allows for case-insensitive matching. In this example, 'FOOBAR' matches the pattern 'foo*' when case sensitivity is turned off.
const wildcard = require('wildcard-match');
const isMatch = wildcard('foo*', { caseSensitive: false })('FOOBAR');
console.log(isMatch); // true
Custom Wildcard Characters
This feature allows you to define custom wildcard characters. In this example, '#' is used as the wildcard character instead of the default '*'.
const wildcard = require('wildcard-match');
const isMatch = wildcard('foo#', { wildcard: '#' })('foo123');
console.log(isMatch); // true
Other packages similar to wildcard-match
minimatch
Minimatch is a powerful glob matching library that supports a wide range of glob patterns. It is more feature-rich compared to wildcard-match, offering advanced pattern matching capabilities.
micromatch
Micromatch is a fast and lightweight glob matcher that supports extended glob patterns and advanced matching features. It is known for its performance and flexibility, making it a good alternative to wildcard-match.
multimatch
Multimatch is a library that allows you to match multiple glob patterns against a list of strings. It is built on top of minimatch and provides additional functionality for handling multiple patterns efficiently.
wildcard-match
A function that matches two glob-like patterns with each other. It has an advantage over other similar libraries in that it allows both samples to have wildcards.
Installation
npm install --save wildcard-match
Usage
const match = require('wildcard-match')
match('one/**', 'one/two/three')
match('.', ['one', '**', 'four'], 'one.two.three.four')
match('one.two', 'one.two.*')
Patterns can be either strings or arrays, and can have the following wildcards:
*
for exactly one segment**
for any number of segments (including zero)
If at least one of the samples is a string, a delimiter can be provided as the first argument. If the delimiter is not specified, /
is used.
License
ISC