CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nanomatch

Fast, minimal glob matcher for node.js with complete Bash 4.3 wildcard support

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

collection-operations.mddocs/

Collection Operations

Advanced matching operations for working with arrays and performing logical operations across multiple patterns. These functions provide boolean logic and set operations for pattern matching.

Capabilities

Some Operation

Test if some elements in a collection match any of the given patterns.

/**
 * Test if some elements match any patterns (short-circuit evaluation)
 * @param {String|Array} list - String or array of strings to test
 * @param {String|Array} patterns - One or more patterns to match against
 * @param {Object} options - Optional configuration object
 * @returns {Boolean} True if any elements match any patterns
 */
nanomatch.some(list, patterns, options);

Usage Examples:

const nanomatch = require('nanomatch');

// Test array elements
console.log(nanomatch.some(['foo.js', 'bar.txt'], '*.js'));
//=> true (foo.js matches)

console.log(nanomatch.some(['foo.txt', 'bar.md'], '*.js'));
//=> false (no matches)

// Multiple patterns
console.log(nanomatch.some(['foo.css', 'bar.js'], ['*.js', '*.ts']));
//=> true (bar.js matches *.js)

// With negation patterns
console.log(nanomatch.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
//=> true (bar.js matches the combined pattern)

console.log(nanomatch.some(['foo.js'], ['*.js', '!foo.js']));
//=> false (foo.js is excluded by negation)

// Single string input
console.log(nanomatch.some('test.js', '*.js'));
//=> true

Every Operation

Test if every element in a collection matches at least one of the given patterns.

/**
 * Test if every element matches at least one pattern
 * @param {String|Array} list - String or array of strings to test
 * @param {String|Array} patterns - One or more patterns to match against
 * @param {Object} options - Optional configuration object
 * @returns {Boolean} True if all elements match at least one pattern
 */
nanomatch.every(list, patterns, options);

Usage Examples:

const nanomatch = require('nanomatch');

// All elements must match
console.log(nanomatch.every(['foo.js', 'bar.js'], '*.js'));
//=> true (both match)

console.log(nanomatch.every(['foo.js', 'bar.txt'], '*.js'));
//=> false (bar.txt doesn't match)

// Multiple patterns - each element needs one match
console.log(nanomatch.every(['foo.js', 'bar.css'], ['*.js', '*.css']));
//=> true (foo.js matches *.js, bar.css matches *.css)

// With negation
console.log(nanomatch.every(['bar.js', 'baz.js'], ['*.js', '!foo.js']));
//=> true (both match *.js and neither is foo.js)

console.log(nanomatch.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
//=> false (foo.js is excluded by negation)

// Single string input
console.log(nanomatch.every('test.js', '*.js'));
//=> true

Any Pattern Matching

Test if any of the given patterns match a single string.

/**
 * Test if any patterns match the given string
 * @param {String} str - String to test against patterns
 * @param {String|Array} patterns - One or more patterns to test
 * @param {Object} options - Optional configuration object
 * @returns {Boolean} True if any patterns match the string
 */
nanomatch.any(str, patterns, options);

Usage Examples:

const nanomatch = require('nanomatch');

// Multiple patterns, any can match
console.log(nanomatch.any('foo.js', ['*.txt', '*.js']));
//=> true (matches *.js)

console.log(nanomatch.any('foo.css', ['*.txt', '*.js']));
//=> false (no patterns match)

// Single pattern (equivalent to isMatch)
console.log(nanomatch.any('test.js', '*.js'));
//=> true

// Complex patterns
console.log(nanomatch.any('src/utils.js', ['lib/**', 'src/**']));
//=> true (matches src/**)

// Empty patterns
console.log(nanomatch.any('test.js', []));
//=> false

console.log(nanomatch.any('test.js', ''));
//=> false

All Pattern Matching

Test if all of the given patterns match a single string.

/**
 * Test if all patterns match the given string
 * @param {String} str - String to test against patterns
 * @param {String|Array} patterns - One or more patterns that must all match
 * @param {Object} options - Optional configuration object
 * @returns {Boolean} True if all patterns match the string
 */
nanomatch.all(str, patterns, options);

Usage Examples:

const nanomatch = require('nanomatch');

// All patterns must match
console.log(nanomatch.all('foo.js', ['foo*', '*.js']));
//=> true (matches both patterns)

console.log(nanomatch.all('bar.js', ['foo*', '*.js']));
//=> false (doesn't match foo*)

// Single pattern
console.log(nanomatch.all('test.js', '*.js'));
//=> true

// Complex patterns
console.log(nanomatch.all('src/utils.js', ['src/**', '**/utils.js']));
//=> true (matches both)

// With negation (all patterns including negation must match)
console.log(nanomatch.all('bar.js', ['*.js', '!foo.js']));
//=> true (matches *.js and is not foo.js)

console.log(nanomatch.all('foo.js', ['*.js', '!foo.js']));
//=> false (matches *.js but fails !foo.js)

Negation Filtering

Return elements that do not match any of the given patterns.

/**
 * Return strings that do not match any patterns
 * @param {Array} list - Array of strings to filter
 * @param {String|Array} patterns - Patterns to filter out
 * @param {Object} options - Optional configuration object
 * @returns {Array} Array of strings that don't match any patterns
 */
nanomatch.not(list, patterns, options);

Usage Examples:

const nanomatch = require('nanomatch');

// Basic negation filtering
const files = ['foo.js', 'bar.txt', 'baz.js', 'qux.md'];
console.log(nanomatch.not(files, '*.js'));
//=> ['bar.txt', 'qux.md']

// Multiple patterns
console.log(nanomatch.not(files, ['*.js', '*.md']));
//=> ['bar.txt']

// Complex patterns
const paths = ['src/app.js', 'lib/utils.js', 'test/spec.js', 'docs/readme.md'];
console.log(nanomatch.not(paths, '**/*.js'));
//=> ['docs/readme.md']

// With ignore option (double negation)
console.log(nanomatch.not(files, '*.js', { ignore: '*.txt' }));
//=> ['qux.md'] (excludes *.js, then ignores *.txt from remaining)

// Empty array for universal patterns
console.log(nanomatch.not(files, '**'));
//=> []

console.log(nanomatch.not(files, '*'));
//=> [] (all files match *)

Logical Relationships

const files = ['a.js', 'b.txt', 'c.js'];
const jsPattern = '*.js';

// These relationships hold:
console.log(nanomatch.some(files, jsPattern));   //=> true
console.log(nanomatch.every(files, jsPattern));  //=> false
console.log(nanomatch.not(files, jsPattern));    //=> ['b.txt']

// any() and all() work on single strings vs multiple patterns
const str = 'test.js';
const patterns = ['test*', '*.js'];

console.log(nanomatch.any(str, patterns));  //=> true (matches at least one)
console.log(nanomatch.all(str, patterns));  //=> true (matches all)

Performance Considerations

  • some() uses short-circuit evaluation - stops at first match
  • every() stops at first non-match
  • any() stops at first matching pattern
  • all() must test every pattern
  • All functions benefit from nanomatch's internal caching

Error Handling

// TypeError for invalid string inputs
try {
  nanomatch.any(123, '*.js');
} catch (error) {
  console.log(error.message);
  //=> 'expected a string: "123"'
}

try {
  nanomatch.all(null, '*.js');
} catch (error) {
  console.log(error.message);
  //=> 'expected a string: "null"'
}

// Empty string handling
console.log(nanomatch.some('', ''));     //=> false
console.log(nanomatch.any('', ''));      //=> false
console.log(nanomatch.all('', ''));      //=> false

docs

collection-operations.md

content-matching.md

core-matching.md

index.md

matcher-creation.md

regex-compilation.md

tile.json