anymatch
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
normalize-path | 3.0.0 | 3.48 kB | MIT | prod | |
picomatch | 2.3.1 | 23.72 kB | MIT | prod |
Anymatch is a useful JavaScript module designed to facilitate string matching against configurable strings, globs, regular expressions, or functions. With a particular emphasis on file paths, its functionality plays an integral role in allowing user-configurable designs that are flexibly designed. Anymatch accomplishes its objectives by directly matching a string, using a string with glob patterns, conducting regular expression tests, or through a function that takes test string as an argument and returns a truthy value if a match should be made.
To use Anymatch, you begin by installing it via npm using the command npm install anymatch
. After installation, it can be used by invoking the anymatch function and passing in the matchers and testString.
Here's a quick code example:
const anymatch = require('anymatch');
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && 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
// returnIndex = true
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
Anymatch also supports curried functions, providing a function that is already bound to the provided matching criteria.
The details and documentation on how to use Anymatch can be found on its GitHub page at https://github.com/micromatch/anymatch. These docs provide a comprehensive guide on how to use Anymatch, covering all the parameters and options, and also illustrating examples on how to best utilize this JavaScript module.