### Create pre-configured instances with defaults Source: https://context7.com/isaacs/minimatch/llms.txt Creates a new minimatch instance with preset options to reduce configuration repetition. ```javascript import { defaults } from 'minimatch' // Create minimatch with default options const mm = defaults({ nocase: true, dot: true }) // All subsequent calls use those defaults mm('README.md', '*.MD') // true (case insensitive) mm('.gitignore', '*ignore') // true (dot files matched) // Use the configured Minimatch class const matcher = new mm.Minimatch('**/*.js') matcher.match('src/App.JS') // true (inherits nocase) // Override defaults for specific calls mm('test.JS', '*.js', { nocase: false }) // false (override to case sensitive) // Chain defaults const strictMm = defaults({ noglobstar: true }) const relaxedMm = strictMm.defaults({ dot: true }) strictMm('a/b/c.js', '**/*.js') // false (** treated as *) relaxedMm('.env', '*') // true (dot files matched) ``` -------------------------------- ### platform Source: https://github.com/isaacs/minimatch/blob/main/README.md Specifies the operating system platform for which path matching should be optimized. Setting this to 'win32' enables Windows-specific behaviors like handling UNC paths and treating backslashes as separators. ```APIDOC ## platform ### Description When set to `win32`, this will trigger all windows-specific behaviors (special handling for UNC paths, and treating `\` as separators in file paths for comparison.) Defaults to the value of `process.platform`. ``` -------------------------------- ### Main Export: minimatch Source: https://github.com/isaacs/minimatch/blob/main/README.md Tests a path against a pattern using the provided options. ```APIDOC ## minimatch(path, pattern, options) ### Description Tests a path against the pattern using the options. ### Parameters #### Path Parameters - **path** (string) - Required - The path to test. - **pattern** (string) - Required - The glob pattern to match against. - **options** (object) - Optional - Configuration options for minimatch. ### Request Example ```javascript var isJS = minimatch(file, '*.js', { matchBase: true }) ``` ``` -------------------------------- ### Configure Minimatch Options Source: https://context7.com/isaacs/minimatch/llms.txt Use these options to control case sensitivity, dotfile matching, brace expansion, globstar behavior, and platform-specific path handling. ```javascript import { minimatch, Minimatch } from 'minimatch' // Case-insensitive matching minimatch('FILE.JS', '*.js', { nocase: true }) // true // Match dotfiles (hidden files) minimatch('.gitignore', '*', { dot: true }) // true // Disable brace expansion minimatch('file.js', 'file.{js,ts}', { nobrace: true }) // false (literal match) // Disable globstar minimatch('a/b/c.js', '**/*.js', { noglobstar: true }) // false (** = single *) // Disable extended globs minimatch('file.js', '*.+(js|ts)', { noext: true }) // false // Match basename only minimatch('/path/to/file.js', '*.js', { matchBase: true }) // true // Partial matching for path traversal minimatch('/a/b', '/a/*/c/d', { partial: true }) // true (might be /a/b/c/d) minimatch('/x/y/z', '/a/**/z', { partial: true }) // false (x !== a) // Platform-specific handling const winMatcher = new Minimatch('src/**/*.js', { platform: 'win32' }) winMatcher.match('src\\utils\\helper.js') // true (backslash as separator) // Windows paths without escape minimatch('path\\to\\file.js', 'path\\to\\*.js', { windowsPathsNoEscape: true }) // Optimization level for filesystem walking new Minimatch('a/*/../*', { optimizationLevel: 2 }) // Optimizes to a/* // Debug output minimatch('test.js', '*.js', { debug: true }) // Logs matching process to stderr ``` -------------------------------- ### Instantiate Minimatch Class Source: https://github.com/isaacs/minimatch/blob/main/README.md Create a reusable Minimatch object by instantiating the Minimatch class with a pattern and optional configuration. ```javascript var Minimatch = require('minimatch').Minimatch var mm = new Minimatch(pattern, options) ``` -------------------------------- ### Parsing and Analyzing Glob Patterns with AST Source: https://context7.com/isaacs/minimatch/llms.txt Demonstrates how to parse a glob pattern into an AST, inspect its properties, and convert it into a RegExp or JSON representation. ```javascript import { AST } from 'minimatch' // Parse a glob pattern into an AST const ast = AST.fromGlob('src/**/*.{js,ts}') // Convert back to string console.log(ast.toString()) // 'src/**/*.{js,ts}' // Get pattern type (null for root, or extglob type) console.log(ast.type) // null // Check if pattern has magic characters console.log(ast.hasMagic) // true // Convert to matching pattern (RegExp or string) const pattern = ast.toMMPattern() console.log(pattern) // RegExp object // Get regexp source const [re, body, hasMagic, uflag] = ast.toRegExpSource() console.log(re) // Regexp source string console.log(hasMagic) // true console.log(uflag) // true if unicode flag needed // JSON representation for debugging console.log(JSON.stringify(ast.toJSON(), null, 2)) // Parse extglob patterns const extAst = AST.fromGlob('+(foo|bar)') console.log(extAst.type) // null (root) console.log(extAst.toString()) // '+(foo|bar)' ``` -------------------------------- ### Basic minimatch Usage Source: https://github.com/isaacs/minimatch/blob/main/README.md Use the main minimatch export to test a path against a pattern with specified options. ```javascript var isJS = minimatch(file, '*.js', { matchBase: true }) ``` -------------------------------- ### Match Files Against a Pattern List Source: https://github.com/isaacs/minimatch/blob/main/README.md Use minimatch.match to test a list of files against a pattern, similar to fnmatch or glob. If no matches are found and nonull option is set, returns a list containing the pattern itself. ```javascript var javascripts = minimatch.match(fileList, '*.js', { matchBase: true }) ``` -------------------------------- ### Utility Function: minimatch.match Source: https://github.com/isaacs/minimatch/blob/main/README.md Matches a list of files against a pattern. ```APIDOC ## minimatch.match(list, pattern, options) ### Description Match against the list of files, in the style of fnmatch or glob. If nothing is matched, and options.nonull is set, then return a list containing the pattern itself. ### Parameters #### Path Parameters - **list** (array) - Required - An array of file paths to match against. - **pattern** (string) - Required - The glob pattern to match. - **options** (object) - Optional - Configuration options for minimatch. ### Request Example ```javascript var javascripts = minimatch.match(fileList, '*.js', { matchBase: true }) ``` ``` -------------------------------- ### Partial Path Matching with Minimatch Source: https://github.com/isaacs/minimatch/blob/main/README.md Use the `partial: true` option to compare a partial path against a pattern. This is useful when the full path is not yet known but you need to ensure it won't lead to a non-matching path. ```javascript minimatch('/a/b', '/a/*/c/d', { partial: true }) // true, might be /a/b/c/d minimatch('/a/b', '/**/d', { partial: true }) // true, might be /a/b/.../d minimatch('/x/y/z', '/a/**/z', { partial: true }) // false, because x !== a ``` -------------------------------- ### Minimatch Options Source: https://github.com/isaacs/minimatch/blob/main/README.md Configuration options that can be passed to minimatch functions. ```APIDOC ## Options All options are `false` by default. ### debug Dump a ton of stuff to stderr. ### nobrace Do not expand `{a,b}` and `{1..3}` brace sets. ### noglobstar Disable `**` matching against multiple folder names. ### dot Allow patterns to match filenames starting with a period, even if the pattern does not explicitly have a period in that spot. Note that by default, `a/**/b` will **not** match `a/.d/b`, unless `dot` is set. ### noext Disable "extglob" style patterns like `+(a|b)`. ### nocase Perform a case-insensitive match. ``` -------------------------------- ### Minimatch Class Source: https://context7.com/isaacs/minimatch/llms.txt Creates a reusable pattern matcher for matching multiple paths against the same pattern. ```APIDOC ## Minimatch(pattern) ### Description Creates a reusable pattern matcher instance. Useful for performance when matching multiple paths against the same pattern. ### Methods - **match(path)**: Returns true if the path matches the pattern. - **makeRe()**: Returns the compiled regular expression for the pattern. - **hasMagic()**: Returns true if the pattern contains magic characters like ** or {}. ``` -------------------------------- ### Use Extended Glob Patterns Source: https://context7.com/isaacs/minimatch/llms.txt Implement bash-style extended glob patterns for complex matching, including alternatives, optionals, and negations. ```javascript import { minimatch } from 'minimatch' // @(pattern) - Match exactly one of the patterns minimatch('foo.js', '@(foo|bar).js') // true minimatch('baz.js', '@(foo|bar).js') // false // ?(pattern) - Match zero or one of the patterns minimatch('foo.js', '?(foo).js') // true minimatch('.js', '?(foo).js') // true (zero occurrences) minimatch('foofoo.js', '?(foo).js') // false // *(pattern) - Match zero or more of the patterns minimatch('', '*(foo)') // true minimatch('foo', '*(foo)') // true minimatch('foofoo', '*(foo)') // true // +(pattern) - Match one or more of the patterns minimatch('foo', '+(foo)') // true minimatch('foofoo', '+(foo)') // true minimatch('', '+(foo)') // false (requires at least one) // !(pattern) - Match anything except the pattern minimatch('bar.js', '!(foo).js') // true minimatch('foo.js', '!(foo).js') // false // Complex combinations minimatch('test.spec.js', '*.+(spec|test).js') // true minimatch('index.js', '!(*.spec|*.test).js') // true minimatch('app.test.js', '!(*.spec|*.test).js') // false // Nested extglobs minimatch('abc', '@(a|@(b|c))*') // true minimatch('abcabc', '@(a|@(b|c))*') // true ``` -------------------------------- ### Perform Basic Pattern Matching Source: https://context7.com/isaacs/minimatch/llms.txt Use the minimatch function to test if a path string matches a specific glob pattern. ```javascript import { minimatch } from 'minimatch' // Basic wildcard matching minimatch('bar.foo', '*.foo') // true - matches any file ending in .foo minimatch('bar.foo', '*.bar') // false - doesn't match .bar extension minimatch('src/index.js', '**/*.js') // true - matches any .js file in any directory // Question mark matches single character minimatch('cat', 'c?t') // true - ? matches 'a' minimatch('cart', 'c?t') // false - ? only matches one character // Character classes minimatch('file1.txt', 'file[0-9].txt') // true - matches file with single digit minimatch('fileA.txt', 'file[a-z].txt') // false - case sensitive by default // Negation patterns minimatch('foo.js', '!*.ts') // true - not a TypeScript file minimatch('bar.ts', '!*.ts') // false - is a TypeScript file ``` -------------------------------- ### Utility Function: minimatch.makeRe Source: https://github.com/isaacs/minimatch/blob/main/README.md Creates a regular expression object from a glob pattern. ```APIDOC ## minimatch.makeRe(pattern, options) ### Description Make a regular expression object from the pattern. ### Parameters #### Path Parameters - **pattern** (string) - Required - The glob pattern to convert to a regular expression. - **options** (object) - Optional - Configuration options for minimatch. ### Request Example ```javascript var regex = minimatch.makeRe('*.js'); ``` ``` -------------------------------- ### braceExpand(pattern) Source: https://context7.com/isaacs/minimatch/llms.txt Expands brace patterns into multiple string variations. ```APIDOC ## braceExpand(pattern) ### Description Expands brace patterns into an array of string variations. Supports comma-separated alternatives, numeric ranges, and alphabetic ranges. ### Parameters - **pattern** (string) - Required - The brace pattern to expand. ### Response - **result** (Array) - An array of expanded string variations. ``` -------------------------------- ### Convert glob to RegExp with makeRe Source: https://context7.com/isaacs/minimatch/llms.txt Generates a JavaScript RegExp object from a glob pattern for custom matching logic. ```javascript import { makeRe } from 'minimatch' // Create regex from glob pattern const jsRegex = makeRe('*.js') console.log(jsRegex) // /^(?! defaults)(?! .)[^/]*?\.js$/ console.log(jsRegex.test('app.js')) // true console.log(jsRegex.test('app.ts')) // false console.log(jsRegex.test('.hidden.js')) // false (dots not matched by default) // Globstar pattern const deepRegex = makeRe('src/**/*.ts') console.log(deepRegex.test('src/index.ts')) // true console.log(deepRegex.test('src/utils/helper.ts')) // true console.log(deepRegex.test('lib/index.ts')) // false // With options const noCaseRegex = makeRe('*.JS', { nocase: true }) console.log(noCaseRegex.test('app.js')) // true console.log(noCaseRegex.test('app.JS')) // true // Extended glob patterns const extRegex = makeRe('*.+(js|ts|jsx|tsx)') console.log(extRegex.test('app.js')) // true console.log(extRegex.test('app.tsx')) // true console.log(extRegex.test('app.css')) // false ``` -------------------------------- ### minimatch(path, pattern) Source: https://context7.com/isaacs/minimatch/llms.txt Tests whether a path string matches a glob pattern. ```APIDOC ## minimatch(path, pattern) ### Description Tests whether a path string matches a glob pattern. Returns true if the path matches the pattern, false otherwise. ### Parameters - **path** (string) - Required - The path string to test. - **pattern** (string) - Required - The glob pattern to match against. ### Response - **result** (boolean) - Returns true if the path matches the pattern. ``` -------------------------------- ### Create a Filter Function with minimatch.filter Source: https://github.com/isaacs/minimatch/blob/main/README.md Use minimatch.filter to create a function suitable for Array.filter, which tests supplied arguments against a pattern. ```javascript var javascripts = fileList.filter( minimatch.filter('*.js', { matchBase: true }), ) ``` -------------------------------- ### Create a Regular Expression from a Pattern Source: https://github.com/isaacs/minimatch/blob/main/README.md Use minimatch.makeRe to generate a regular expression object from a given glob pattern. ```javascript minimatch.makeRe(pattern, options) ``` -------------------------------- ### Defaults Function Source: https://context7.com/isaacs/minimatch/llms.txt The `defaults` function creates a new minimatch instance with preset options. This is useful for reducing boilerplate code when you consistently use the same set of options across multiple matching operations. You can also chain `defaults` calls to build up configurations. ```APIDOC ## Defaults Function The `defaults` function creates a new minimatch instance with preset options, reducing boilerplate when using the same options repeatedly. ### Method `defaults(options: object) => MinimatchInstance` ### Parameters #### Request Body (Implicit) - `options` (object) - An object containing default options to apply. - `nocase` (boolean) - If true, performs case-insensitive matching. - `dot` (boolean) - If true, patterns will match dot files (files starting with '.'). - `noglobstar` (boolean) - If true, the `**` pattern will not be treated as a globstar. ### Request Example ```javascript import { defaults } from 'minimatch' // Create minimatch with default options const mm = defaults({ nocase: true, dot: true }) // All subsequent calls use those defaults mm('README.md', '*.MD') // true (case insensitive) mm('.gitignore', '*ignore') // true (dot files matched) // Use the configured Minimatch class const matcher = new mm.Minimatch('**/*.js') matcher.match('src/App.JS') // true (inherits nocase) // Override defaults for specific calls mm('test.JS', '*.js', { nocase: false }) // false (override to case sensitive) // Chain defaults const strictMm = defaults({ noglobstar: true }) const relaxedMm = strictMm.defaults({ dot: true }) strictMm('a/b/c.js', '**/*.js') // false (** treated as *) relaxedMm('.env', '*') // true (dot files matched) ``` ### Response #### Success Response (200) - `MinimatchInstance` - A minimatch instance configured with the provided default options. This instance has a `Minimatch` class property and a `match` method. ``` -------------------------------- ### Match Multiple Files Source: https://context7.com/isaacs/minimatch/llms.txt The `match` function filters an array of paths against a glob pattern, returning only the paths that match. It supports various options like `dot` for hidden files, `nonull` to return the pattern if no matches are found, and `nocase` for case-insensitive matching. ```APIDOC ## Match Multiple Files The `match` function filters an array of paths against a pattern, returning only the matching paths. ### Method `match(files: string[], pattern: string, options?: object) => string[]` ### Parameters #### Request Body (Implicit) - `files` (string[]) - An array of file paths to filter. - `pattern` (string) - The glob pattern to match against. - `options` (object) - Optional configuration object. - `dot` (boolean) - If true, patterns will match dot files (files starting with '.'). - `nonull` (boolean) - If true, returns the pattern if no files match. - `nocase` (boolean) - If true, performs case-insensitive matching. ### Request Example ```javascript import { match } from 'minimatch' const files = [ 'app.js', 'app.ts', 'index.html', 'styles.css', 'test.spec.js', '.gitignore', '.env' ] // Match all JavaScript files match(files, '*.js') // Result: ['app.js', 'test.spec.js'] // Match with dot option to include hidden files match(files, '.*', { dot: true }) // Result: ['.gitignore', '.env'] // Match with nonull option - return pattern if no matches match(files, '*.py', { nonull: true }) // Result: ['*.py'] match(files, '*.py') // Result: [] // Case-insensitive matching match(['File.JS', 'file.js', 'FILE.TS'], '*.js', { nocase: true }) // Result: ['File.JS', 'file.js'] ``` ### Response #### Success Response (200) - `string[]` - An array of file paths that match the pattern. ``` -------------------------------- ### Make Regular Expression Source: https://context7.com/isaacs/minimatch/llms.txt The `makeRe` function converts a glob pattern into a JavaScript RegExp object. This is useful for performing custom matching logic or integrating with other regex-based tools. Options like `nocase` can be passed to influence the generated regex. ```APIDOC ## Make Regular Expression The `makeRe` function converts a glob pattern into a JavaScript RegExp object for custom matching logic. ### Method `makeRe(pattern: string, options?: object) => RegExp` ### Parameters #### Request Body (Implicit) - `pattern` (string) - The glob pattern to convert. - `options` (object) - Optional configuration object. - `nocase` (boolean) - If true, the generated RegExp will be case-insensitive. ### Request Example ```javascript import { makeRe } from 'minimatch' // Create regex from glob pattern const jsRegex = makeRe('*.js') console.log(jsRegex) // /^(?!\[/\*\*\/)[^/]*?\.js$/ console.log(jsRegex.test('app.js')) // true console.log(jsRegex.test('app.ts')) // false console.log(jsRegex.test('.hidden.js')) // false (dots not matched by default) // Globstar pattern const deepRegex = makeRe('src/**/*.ts') console.log(deepRegex.test('src/index.ts')) // true console.log(deepRegex.test('src/utils/helper.ts')) // true console.log(deepRegex.test('lib/index.ts')) // false // With options const noCaseRegex = makeRe('*.JS', { nocase: true }) console.log(noCaseRegex.test('app.js')) // true console.log(noCaseRegex.test('app.JS')) // true // Extended glob patterns const extRegex = makeRe('*.+(js|ts|jsx|tsx)') console.log(extRegex.test('app.js')) // true console.log(extRegex.test('app.tsx')) // true console.log(extRegex.test('app.css')) // false ``` ### Response #### Success Response (200) - `RegExp` - A JavaScript regular expression object generated from the glob pattern. ``` -------------------------------- ### filter(pattern, options) Source: https://context7.com/isaacs/minimatch/llms.txt Returns a predicate function for use with Array.filter() to filter file lists. ```APIDOC ## filter(pattern, options) ### Description Returns a predicate function suitable for use with Array.filter() to filter lists of strings based on a glob pattern. ### Parameters - **pattern** (string) - Required - The glob pattern to filter by. - **options** (object) - Optional - Configuration options for the matching process. ### Response - **predicate** (function) - A function that takes a string and returns a boolean. ``` -------------------------------- ### Utility Function: minimatch.unescape Source: https://github.com/isaacs/minimatch/blob/main/README.md Un-escapes a glob string that may contain escaped characters. ```APIDOC ## minimatch.unescape(pattern, options = {}) ### Description Un-escape a glob string that may contain some escaped characters. If the `windowsPathsNoEscape` option is used, then square-brace escapes are removed, but not backslash escapes. For example, it will turn the string `'[*]'` into `*`, but it will not turn `'\*'` into `'*'`, because `\` is a path separator in `windowsPathsNoEscape` mode. When `windowsPathsNoEscape` is not set, then both brace escapes and backslash escapes are removed. Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped or unescaped. ### Parameters #### Path Parameters - **pattern** (string) - Required - The glob pattern to unescape. - **options** (object) - Optional - Configuration options for unescaping. ### Request Example ```javascript var unescapedPattern = minimatch.unescape('\*.js'); ``` ``` -------------------------------- ### Use the Minimatch Class for Reusable Matching Source: https://context7.com/isaacs/minimatch/llms.txt The Minimatch class is optimized for scenarios where the same pattern is matched against multiple paths repeatedly. ```javascript import { Minimatch } from 'minimatch' // Create a reusable matcher const mm = new Minimatch('**/*.{js,ts}') // Match multiple files const files = ['src/index.js', 'src/utils.ts', 'README.md', 'package.json'] const matched = files.filter(f => mm.match(f)) // Result: ['src/index.js', 'src/utils.ts'] // Access pattern properties console.log(mm.pattern) // '**/*.{js,ts}' console.log(mm.negate) // false console.log(mm.comment) // false console.log(mm.empty) // false // Check if pattern contains magic characters console.log(mm.hasMagic()) // true - contains ** and {} // Get the compiled regular expression const regex = mm.makeRe() console.log(regex) // /^(?:(?:(?!(?:\/|^)(?:\.{1,2})($|\/)).)*?\/[^/]*?\.(?:js|ts))$/ console.log(regex.test('src/app.js')) // true ``` -------------------------------- ### optimizationLevel Source: https://github.com/isaacs/minimatch/blob/main/README.md Controls the level of optimization applied to patterns before matching. Higher levels offer more aggressive optimizations, potentially improving performance but with a slight risk of failing to match literal strings that lower levels would match. ```APIDOC ## optimizationLevel ### Description A number indicating the level of optimization that should be done to the pattern prior to parsing and using it for matches. Globstar parts `**` are always converted to `*` when `noglobstar` is set, and multiple adjacent `**` parts are converted into a single `**` (ie, `a/**/**/b` will be treated as `a/**/b`, as this is equivalent in all cases). ### Levels: - `0` - Make no further changes. In this mode, `.` and `..` are maintained in the pattern, meaning that they must also appear in the same position in the test path string. Eg, a pattern like `a/*/../c` will match the string `a/b/../c` but not the string `a/c`. - `1` - (default) Remove cases where a double-dot `..` follows a pattern portion that is not `**`, `.`, `..`, or empty `''`. For example, the pattern `./a/b/../*` is converted to `./a/*`, and so it will match the path string `./a/c`, but not the path string `./a/b/../c`. Dots and empty path portions in the pattern are preserved. - `2` (or higher) - Much more aggressive optimizations, suitable for use with file-walking cases: - Remove cases where a double-dot `..` follows a pattern portion that is not `**`, `.`, or empty `''`. Remove empty and `.` portions of the pattern, where safe to do so (ie, anywhere other than the last position, the first position, or the second position in a pattern starting with `/`, as this may indicate a UNC path on Windows). - Convert patterns containing `
/**/../

/` into the equivalent `

/{..,**}/

/`, where `

` is a a pattern portion other than `.`, `..`, `**`, or empty `''`. - Dedupe patterns where a `**` portion is present in one and omitted in another, and it is not the final path portion, and they are otherwise equivalent. So `{a/**/b,a/b}` becomes `a/**/b`, because `**` matches against an empty path portion. - Dedupe patterns where a `*` portion is present in one, and a non-dot pattern other than `**`, `.`, `..`, or `''` is in the same position in the other. So `a/{*,x}/b` becomes `a/*/b`, because `*` can match against `x`. While these optimizations improve the performance of file-walking use cases such as [glob](http://npm.im/glob) (ie, the reason this module exists), there are cases where it will fail to match a literal string that would have been matched in optimization level 1 or 0. Specifically, while the `Minimatch.match()` method will optimize the file path string in the same ways, resulting in the same matches, it will fail when tested with the regular expression provided by `Minimatch.makeRe()`, unless the path string is first processed with `minimatch.levelTwoFileOptimize()` or similar. ``` -------------------------------- ### Utility Function: minimatch.filter Source: https://github.com/isaacs/minimatch/blob/main/README.md Returns a function that tests its supplied argument, suitable for use with Array.filter. ```APIDOC ## minimatch.filter(pattern, options) ### Description Returns a function that tests its supplied argument, suitable for use with `Array.filter`. ### Parameters #### Path Parameters - **pattern** (string) - Required - The glob pattern to filter by. - **options** (object) - Optional - Configuration options for minimatch. ### Request Example ```javascript var javascripts = fileList.filter( minimatch.filter('*.js', { matchBase: true }), ) ``` ``` -------------------------------- ### Filter paths with match Source: https://context7.com/isaacs/minimatch/llms.txt Filters an array of file paths against a glob pattern. Supports options like dot, nonull, and nocase. ```javascript import { match } from 'minimatch' const files = [ 'app.js', 'app.ts', 'index.html', 'styles.css', 'test.spec.js', '.gitignore', '.env' ] // Match all JavaScript files match(files, '*.js') // Result: ['app.js', 'test.spec.js'] // Match with dot option to include hidden files match(files, '.*', { dot: true }) // Result: ['.gitignore', '.env'] // Match with nonull option - return pattern if no matches match(files, '*.py', { nonull: true }) // Result: ['*.py'] match(files, '*.py') // Result: [] // Case-insensitive matching match(['File.JS', 'file.js', 'FILE.TS'], '*.js', { nocase: true }) // Result: ['File.JS', 'file.js'] ``` -------------------------------- ### Utility Function: minimatch.escape Source: https://github.com/isaacs/minimatch/blob/main/README.md Escapes all magic characters in a glob pattern. ```APIDOC ## minimatch.escape(pattern, options = {}) ### Description Escape all magic characters in a glob pattern, so that it will only ever match literal strings. If the `windowsPathsNoEscape` option is used, then characters are escaped by wrapping in `[]`, because a magic character wrapped in a character class can only be satisfied by that exact character. Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped or unescaped. ### Parameters #### Path Parameters - **pattern** (string) - Required - The glob pattern to escape. - **options** (object) - Optional - Configuration options for escaping. ### Request Example ```javascript var escapedPattern = minimatch.escape('*.js'); ``` ``` -------------------------------- ### Expand Brace Patterns Source: https://context7.com/isaacs/minimatch/llms.txt The braceExpand function converts brace patterns into an array of all possible string variations. ```javascript import { braceExpand } from 'minimatch' // Comma-separated alternatives braceExpand('file.{js,ts,jsx,tsx}') // Result: ['file.js', 'file.ts', 'file.jsx', 'file.tsx'] // Numeric ranges braceExpand('file{1..5}.txt') // Result: ['file1.txt', 'file2.txt', 'file3.txt', 'file4.txt', 'file5.txt'] // Alphabetic ranges braceExpand('{a..e}.txt') // Result: ['a.txt', 'b.txt', 'c.txt', 'd.txt', 'e.txt'] // Nested braces braceExpand('src/{components,utils}/{index,helpers}.{js,ts}') // Result: ['src/components/index.js', 'src/components/index.ts', // 'src/components/helpers.js', 'src/components/helpers.ts', // 'src/utils/index.js', 'src/utils/index.ts', // 'src/utils/helpers.js', 'src/utils/helpers.ts'] // Combined patterns braceExpand('test{1..3}.{spec,test}.js') // Result: ['test1.spec.js', 'test1.test.js', 'test2.spec.js', // 'test2.test.js', 'test3.spec.js', 'test3.test.js'] ``` -------------------------------- ### Perform Glob Matching Source: https://github.com/isaacs/minimatch/blob/main/README.md Use the minimatch function to test if a string matches a glob pattern. Supports both ESM and CommonJS module loading. ```javascript // hybrid module, load with require() or import import { minimatch } from 'minimatch' // or: const { minimatch } = require('minimatch') minimatch('bar.foo', '*.foo') // true! minimatch('bar.foo', '*.bar') // false! minimatch('bar.foo', '*.+(bar|foo)', { debug: true }) // true, and noisy! ``` -------------------------------- ### maxGlobstarRecursion Source: https://github.com/isaacs/minimatch/blob/main/README.md Sets the maximum number of non-adjacent `**` patterns that can be recursively walked down. The default is 200, which is generally sufficient for most patterns. Exceeding this limit results in a non-match for security and performance reasons. ```APIDOC ## maxGlobstarRecursion ### Description Max number of non-adjacent `**` patterns to recursively walk down. The default of `200` is almost certainly high enough for most purposes, and can handle absurdly excessive patterns. If the limit is exceeded (which would require very excessively long patterns and paths containing lots of `**` patterns!), then it is treated as non-matching, even if the path would normally match the pattern provided. That is, this is an intentional false negative, deemed an acceptable break in correctness for security and performance. ``` -------------------------------- ### Apply POSIX Character Classes Source: https://context7.com/isaacs/minimatch/llms.txt Utilize POSIX character classes within bracket expressions to match specific character types with Unicode support. ```javascript import { minimatch } from 'minimatch' // [:alpha:] - Alphabetic characters (Unicode aware) minimatch('abc', '[[:alpha:]]*') // true minimatch('123', '[[:alpha:]]*') // false minimatch('cafe', '[[:alpha:]]*') // true (includes accented chars) // [:digit:] - Numeric digits minimatch('123', '[[:digit:]]*') // true minimatch('12a', '[[:digit:]]*') // false // [:alnum:] - Alphanumeric characters minimatch('abc123', '[[:alnum:]]*') // true minimatch('abc-123', '[[:alnum:]]*') // false (hyphen not alnum) // [:space:] - Whitespace characters minimatch(' ', '[[:space:]]') // true minimatch('\t', '[[:space:]]') // true // [:upper:] and [:lower:] - Case-specific matching minimatch('ABC', '[[:upper:]]*') // true minimatch('abc', '[[:lower:]]*') // true // [:xdigit:] - Hexadecimal digits minimatch('deadbeef', '[[:xdigit:]]*') // true minimatch('CAFE42', '[[:xdigit:]]*') // true // Negation with POSIX classes minimatch('!@#', '[^[:alnum:]]*') // true (non-alphanumeric) // Combining POSIX classes with other patterns minimatch('file123.txt', 'file[[:digit:]]*.txt') // true ``` -------------------------------- ### Escape and Unescape Source: https://context7.com/isaacs/minimatch/llms.txt The `escape` function escapes special glob characters so they can be matched literally. The `unescape` function reverses this process. Options like `windowsPathsNoEscape` and `magicalBraces` can modify the escaping behavior. ```APIDOC ## Escape and Unescape The `escape` function escapes magic glob characters to match them literally. The `unescape` function reverses the escaping. ### Method `escape(str: string, options?: object) => string` `unescape(str: string, options?: object) => string` ### Parameters #### Request Body (Implicit) - `str` (string) - The string to escape or unescape. - `options` (object) - Optional configuration object. - `windowsPathsNoEscape` (boolean) - If true, uses `[]` instead of backslash for escaping. - `magicalBraces` (boolean) - If true, escapes brace characters `{}`. ### Request Example ```javascript import { escape, unescape } from 'minimatch' // Escape special glob characters escape('file[1].txt') // 'file\[1\].txt' escape('data*.json') // 'data\*.json' escape('path/to/file?.md') // 'path/to/file\?.md' escape('src/(utils)') // 'src/\(utils\)' // Use escaped pattern in matching import { minimatch } from 'minimatch' const literal = escape('file[1].txt') minimatch('file[1].txt', literal) // true - matches literally minimatch('file1.txt', literal) // false - [] not treated as character class // Windows paths mode - uses [] instead of backslash escape('file*.txt', { windowsPathsNoEscape: true }) // Result: 'file[*].txt' // Escape braces when magicalBraces option is used escape('config.{json,yaml}', { magicalBraces: true }) // Result: 'config.\{json,yaml\}' // Unescape patterns unescape('file\[1\].txt') // 'file[1].txt' unescape('data\*.json') // 'data*.json' unescape('[*].txt', { windowsPathsNoEscape: true }) // '*.txt' ``` ### Response #### Success Response (200) - `string` - The escaped or unescaped string. ``` -------------------------------- ### Escape Magic Characters in a Glob Pattern Source: https://github.com/isaacs/minimatch/blob/main/README.md Use minimatch.escape to escape all magic characters in a glob pattern, ensuring it only matches literal strings. Handles Windows-specific path escaping if the option is used. ```javascript minimatch.escape(pattern, options = {}) ``` -------------------------------- ### maxExtglobRecursion Source: https://github.com/isaacs/minimatch/blob/main/README.md Defines the maximum depth for traversing nested extended globs (e.g., `*(a|b|c)`). The default is 2. Higher values can significantly impact performance. If the limit is hit, the extglob characters are not parsed, and the pattern effectively switches to `noextglob: true` mode for its contents. ```APIDOC ## maxExtglobRecursion ### Description Max depth to traverse for nested extglobs like `*(a|b|c)` Default is 2, which is quite low, but any higher value swiftly results in punishing performance impacts. Note that this is _not_ relevant when the globstar types can be safely coalesced into a single set. For example, `*(a|@(b|c)|d)` would be flattened into `*(a|b|c|d)`. Thus, many common extglobs will retain good performance and never hit this limit, even if they are excessively deep and complicated. If the limit is hit, then the extglob characters are simply not parsed, and the pattern effectively switches into `noextglob: true` mode for the contents of that nested sub-pattern. This will typically _not_ result in a match, but is considered a valid trade-off for security and performance. ``` -------------------------------- ### Unescape a Glob String Source: https://github.com/isaacs/minimatch/blob/main/README.md Use minimatch.unescape to remove escaped characters from a glob string. Behavior differs based on the windowsPathsNoEscape option. ```javascript minimatch.unescape(pattern, options = {}) ``` -------------------------------- ### Escape and unescape glob characters Source: https://context7.com/isaacs/minimatch/llms.txt Escapes magic glob characters to treat them as literals, or reverses the process. Useful for matching filenames containing special characters. ```javascript import { escape, unescape } from 'minimatch' // Escape special glob characters escape('file[1].txt') // 'file\[1\].txt' escape('data*.json') // 'data\*.json' escape('path/to/file?.md') // 'path/to/file\?.md' escape('src/(utils)') // 'src/\(utils\)' // Use escaped pattern in matching import { minimatch } from 'minimatch' const literal = escape('file[1].txt') minimatch('file[1].txt', literal) // true - matches literally minimatch('file1.txt', literal) // false - [] not treated as character class // Windows paths mode - uses [] instead of backslash escape('file*.txt', { windowsPathsNoEscape: true }) // Result: 'file[*].txt' // Escape braces when magicalBraces option is used escape('config.{json,yaml}', { magicalBraces: true }) // Result: 'config.\{json,yaml\}' // Unescape patterns unescape('file\[1\].txt') // 'file[1].txt' unescape('data\*.json') // 'data*.json' unescape('[*].txt', { windowsPathsNoEscape: true }) // '*.txt' ``` -------------------------------- ### Filter Arrays with Glob Patterns Source: https://context7.com/isaacs/minimatch/llms.txt The filter function generates a predicate for Array.filter() to simplify filtering lists of strings based on glob patterns. ```javascript import { filter } from 'minimatch' const files = [ 'src/index.js', 'src/utils.js', 'src/styles.css', 'test/index.test.js', 'README.md', 'package.json' ] // Filter JavaScript files const jsFiles = files.filter(filter('**/*.js')) // Result: ['src/index.js', 'src/utils.js', 'test/index.test.js'] // Filter with options const testFiles = files.filter(filter('**/*.test.js', { matchBase: true })) // Result: ['test/index.test.js'] // Exclude patterns using negation const nonTestFiles = files.filter(filter('!**/*.test.js')) // Result: ['src/index.js', 'src/utils.js', 'src/styles.css', 'README.md', 'package.json'] // Chain multiple filters const srcJsFiles = files .filter(filter('src/**')) .filter(filter('**/*.js')) // Result: ['src/index.js', 'src/utils.js'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.