minimatch
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
brace-expansion | 1.1.11 | 4.14 kB | MIT | prod |
Minimatch is a minimalist matching utility used by npm internally. It utilizes glob expressions, converting them into JavaScript RegExp objects, to perform matching operations. This makes it an essential tool for a variety of tasks involving pattern matching in JavaScript.
To use minimatch in your JavaScript project, you first need to import it. You can either require the module or import it - both ways are supported. After importing, you call the minimatch
function with two parameters - the string you want to test and the pattern you want to match against. For example:
const { minimatch } = require('minimatch');
console.log(minimatch('bar.foo', '*.foo')); // Outputs: true
console.log(minimatch('bar.foo', '*.bar')); // Outputs: false
console.log(minimatch('bar.foo', '*.+(bar|foo)', { debug: true })); // Outputs: true
As seen in the code block above, minimatch supports brace expansion, extended glob matching, Globstar '**' matching, and POSIX character classes - offering a wide variety of pattern matching options.
Now let's look at different operation you can perform. You can create a minimatch object using the minimatch.Minimatch
class. For example:
var Minimatch = require('minimatch').Minimatch
var mm = new Minimatch(pattern, options)
The package also provides several functions to interact with pattern such as the filter()
, makeRe()
, escape()
, unescape()
and match()
methods among others which can be used depending on your specific needs. For instance:
var isJS = minimatch(file, '*.js', { matchBase: true });
var javascripts = fileList.filter(minimatch.filter('*.js', { matchBase: true }));
var javascripts = minimatch.match(fileList, '*.js', { matchBase: true });
The documentation for the minimatch npm package can be found in the README file in its GitHub repository. The repository's URL is git://github.com/isaacs/minimatch.git. The README contains detailed information about usage, features, options and everything you need to effectively utilize the minimatch utility in your JavaScript projects.