minimatch is a JavaScript library that tests file paths against glob patterns. It splits patterns on slashes and matches each segment without converting untrusted patterns into regular expressions vulnerable to ReDoS.
Overview
The library underpins globbing in the Node ecosystem and exposes a main minimatch function, a Minimatch class, filter helpers for arrays, and escape/unescape utilities. Patterns support brace expansion, extended globs, globstars, negation, and POSIX character classes with Unicode-aware alpha matching.
Matching logic relies on a dedicated non-recursive matcher rather than regex compilation from user input, addressing pathological backtracking risks seen in older glob implementations. Documentation still warns that pattern matchers fed untrusted user input need careful threat modeling.
Windows paths receive special handling for UNC paths, drive letters, and case rules, while glob expressions themselves should use forward slashes. Numerous options control dotfile matching, case folding, partial path tests, magic detection, and compatibility with path.join-style Windows patterns.
Consumers integrate via require or ES module import in Node and bundler environments. The API mirrors fnmatch-style list matching and caches recently used compiled patterns for repeated tests against many files.
Key features
- Glob pattern path matching
- Brace expansion and extglobs
- Globstar and POSIX classes
- Negated and comment patterns
- Windows UNC path rules
- Filter and match list helpers
- Pattern escape and unescape
- Non-regex matcher core
Use cases
- Build tool file filtering
- gitignore-style matching
- Directory walk filtering
- npm package include rules
- User-supplied pattern APIs