Fast, minimal glob matcher for node.js with complete Bash 4.3 wildcard support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Primary glob pattern matching functionality for filtering arrays of strings against one or more patterns. These functions form the foundation of nanomatch's pattern matching capabilities.
The primary entry point for nanomatch pattern matching operations.
/**
* Match array of strings against one or more glob patterns
* @param {Array} list - Array of strings to match against patterns
* @param {String|Array} patterns - One or more glob patterns for matching
* @param {Object} options - Optional configuration object
* @returns {Array} Array of strings that match the patterns
*/
function nanomatch(list, patterns, options);Usage Examples:
const nanomatch = require('nanomatch');
// Single pattern matching
const files = ['a.js', 'b.txt', 'c.js'];
console.log(nanomatch(files, '*.js'));
//=> ['a.js', 'c.js']
// Multiple patterns with negation
console.log(nanomatch(files, ['*.js', '!a.js']));
//=> ['c.js']
// Globstar patterns for nested paths
const paths = ['src/index.js', 'lib/utils.js', 'docs/readme.md'];
console.log(nanomatch(paths, 'src/**'));
//=> ['src/index.js']
// Empty results for non-matching patterns
console.log(nanomatch(files, '*.php'));
//=> []Match an array of strings against a single glob pattern.
/**
* Match array of strings against a single glob pattern
* @param {Array} list - Array of strings to match
* @param {String} pattern - Single glob pattern (not array)
* @param {Object} options - Optional configuration object
* @returns {Array} Array of strings matching the pattern
*/
nanomatch.match(list, pattern, options);Usage Examples:
const nanomatch = require('nanomatch');
// Basic pattern matching
const items = ['foo.js', 'bar.txt', 'baz.js'];
console.log(nanomatch.match(items, '*.js'));
//=> ['foo.js', 'baz.js']
// Question mark patterns
console.log(nanomatch.match(['a1', 'a2', 'ab'], 'a?'));
//=> ['a1', 'a2']
// Bracket patterns
console.log(nanomatch.match(['a1', 'b2', 'c3'], '[ab]*'));
//=> ['a1', 'b2']
// With options
console.log(nanomatch.match(['Foo.JS', 'bar.txt'], '*.js', { nocase: true }));
//=> ['Foo.JS']Test whether a single string matches a glob pattern.
/**
* Test if a string matches a glob pattern
* @param {String} string - String to test against pattern
* @param {String} pattern - Glob pattern to match against
* @param {Object} options - Optional configuration object
* @returns {Boolean} True if string matches pattern, false otherwise
*/
nanomatch.isMatch(string, pattern, options);Usage Examples:
const nanomatch = require('nanomatch');
// Basic matching
console.log(nanomatch.isMatch('foo.js', '*.js'));
//=> true
console.log(nanomatch.isMatch('foo.txt', '*.js'));
//=> false
// Globstar matching
console.log(nanomatch.isMatch('src/lib/utils.js', '**/utils.js'));
//=> true
console.log(nanomatch.isMatch('docs/readme.md', 'src/**'));
//=> false
// Negation patterns
console.log(nanomatch.isMatch('test.js', '!*.js'));
//=> false
// Case sensitivity
console.log(nanomatch.isMatch('Foo.JS', '*.js'));
//=> false
console.log(nanomatch.isMatch('Foo.JS', '*.js', { nocase: true }));
//=> true
// Dotfile matching
console.log(nanomatch.isMatch('.gitignore', '*'));
//=> false
console.log(nanomatch.isMatch('.gitignore', '*', { dot: true }));
//=> true* - Matches zero or more characters except path separators** - Matches zero or more directories and subdirectories? - Matches exactly one character except path separators[abc] - Matches any character in the bracket set[a-z] - Matches any character in the range[!abc] or [^abc] - Matches any character not in the set! exclude matches.) require explicit matching or dot: true optionnocase: true for insensitive matching// TypeError for invalid inputs
try {
nanomatch.isMatch(123, '*.js');
} catch (error) {
console.log(error.message);
//=> 'expected a string: "123"'
}
// TypeError for array pattern in match()
try {
nanomatch.match(['foo.js'], ['*.js']);
} catch (error) {
console.log(error.message);
//=> 'expected pattern to be a string'
}
// Empty string handling
console.log(nanomatch.isMatch('', ''));
//=> false
console.log(nanomatch.isMatch('foo', ''));
//=> false