CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-micromatch

Glob matching for javascript/node.js, a replacement and faster alternative to minimatch and multimatch

90

1.50x
Overview
Eval results
Files

boolean-testing.mddocs/

Boolean Testing

Functions that return boolean values for pattern matching tests, including single string tests, collection-based tests, and partial matching capabilities.

Capabilities

String Matching Test

Tests if a single string matches any of the given glob patterns.

/**
 * Returns true if any of the given glob patterns match the specified string
 * @param {string} str - The string to test
 * @param {string|string[]} patterns - One or more glob patterns to use for matching
 * @param {object} options - See available options for changing how matches are performed
 * @returns {boolean} Returns true if any patterns match str
 */
function isMatch(str, patterns, options);

Usage Examples:

const { isMatch } = require('micromatch');

// Basic string matching
console.log(isMatch('foo.js', '*.js')); //=> true
console.log(isMatch('foo.txt', '*.js')); //=> false

// Multiple patterns
console.log(isMatch('a.a', ['b.*', '*.a'])); //=> true

// With options
console.log(isMatch('Foo.JS', '*.js', { nocase: true })); //=> true

Any Method (Alias)

Backwards compatibility alias for isMatch.

/**
 * Alias for isMatch() - backwards compatibility
 * @param {string} str - The string to test
 * @param {string|string[]} patterns - One or more glob patterns
 * @param {object} options - See available options
 * @returns {boolean} Returns true if any patterns match str
 */
micromatch.any = isMatch;

Matcher Function Creation

Creates a reusable matcher function from a glob pattern for efficient repeated testing.

/**
 * Returns a matcher function from the given glob pattern and options
 * @param {string} pattern - Glob pattern
 * @param {object} options - See available options
 * @returns {function} Returns a matcher function that takes a string and returns boolean
 */
function matcher(pattern, options);

Usage Examples:

const { matcher } = require('micromatch');

// Create reusable matcher
const isJavaScript = matcher('*.js');
console.log(isJavaScript('app.js')); //=> true
console.log(isJavaScript('style.css')); //=> false

// With negation
const isNotTest = matcher('!*.test.js');
console.log(isNotTest('app.js')); //=> true
console.log(isNotTest('app.test.js')); //=> false

Partial String Matching

Tests if a string contains a pattern anywhere within it (not just exact matching).

/**
 * Returns true if the given string contains the given pattern
 * @param {string} str - The string to match
 * @param {string|string[]} patterns - Glob pattern to use for matching
 * @param {object} options - See available options for changing how matches are performed
 * @returns {boolean} Returns true if any of the patterns matches any part of str
 */
function contains(str, pattern, options);

Usage Examples:

const { contains } = require('micromatch');

// Partial matching
console.log(contains('aa/bb/cc', '*b')); //=> true
console.log(contains('aa/bb/cc', '*d')); //=> false

// Path segments
console.log(contains('path/to/file.js', 'to')); //=> true

Collection Testing - Some

Tests if some strings in a collection match any of the given patterns.

/**
 * Returns true if some of the strings in the given list match any of the given glob patterns
 * @param {string|string[]} list - The string or array of strings to test
 * @param {string|string[]} patterns - One or more glob patterns to use for matching
 * @param {object} options - See available options for changing how matches are performed
 * @returns {boolean} Returns true if any patterns matches any of the strings in list
 */
function some(list, patterns, options);

Usage Examples:

const { some } = require('micromatch');

console.log(some(['foo.js', 'bar.js'], ['*.js', '!foo.js'])); //=> true
console.log(some(['foo.js'], ['*.js', '!foo.js'])); //=> false

Collection Testing - Every

Tests if every string in a collection matches any of the given patterns.

/**
 * Returns true if every string in the given list matches any of the given glob patterns
 * @param {string|string[]} list - The string or array of strings to test
 * @param {string|string[]} patterns - One or more glob patterns to use for matching
 * @param {object} options - See available options for changing how matches are performed
 * @returns {boolean} Returns true if all patterns matches all of the strings in list
 */
function every(list, patterns, options);

Usage Examples:

const { every } = require('micromatch');

console.log(every('foo.js', ['foo.js'])); //=> true
console.log(every(['foo.js', 'bar.js'], ['*.js'])); //=> true
console.log(every(['foo.js', 'bar.js'], ['*.js', '!foo.js'])); //=> false

All Patterns Matching

Tests if ALL given patterns match a single string (stricter than isMatch which tests if ANY pattern matches).

/**
 * Returns true if all of the given patterns match the specified string
 * @param {string} str - The string to test
 * @param {string|string[]} patterns - One or more glob patterns to use for matching
 * @param {object} options - See available options for changing how matches are performed
 * @returns {boolean} Returns true if all patterns match str
 */
function all(str, patterns, options);

Usage Examples:

const { all } = require('micromatch');

console.log(all('foo.js', ['foo.js'])); //=> true
console.log(all('foo.js', ['*.js', '!foo.js'])); //=> false
console.log(all('foo.js', ['*.js', 'foo.js'])); //=> true
console.log(all('foo.js', ['*.js', 'f*', '*o*', '*o.js'])); //=> true

Error Handling

  • Throws TypeError for invalid string input in contains() function
  • Returns false for non-matching patterns (does not throw)
  • Handles empty strings and patterns gracefully

Install with Tessl CLI

npx tessl i tessl/npm-micromatch

docs

boolean-testing.md

brace-expansion.md

index.md

main-matching.md

pattern-processing.md

utility-functions.md

tile.json