Minimatch is a JavaScript utility library that provides robust glob matching functionality, converting glob expressions into JavaScript `RegExp` objects for efficient pattern matching. It is famously used internally by npm for its file system operations. The current stable version is 10.2.5, with releases typically occurring as needed to address bugs, enhance features, or align with npm's requirements. Key features include support for brace expansion, extended glob matching, globstar (`**`), and Posix character classes (e.g., `[[:alpha:]]`), which are Unicode-aware. A critical aspect of minimatch is its explicit warning regarding Regular Expression Denial of Service (ReDoS) vulnerabilities, advising users to never use untrusted input as glob patterns due to the inherent risks of RegExp-based matching. It also provides specific guidance for Windows users, emphasizing the exclusive use of forward slashes in glob expressions to avoid misinterpretation of backslashes as escape characters.
npm install minimatchVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic glob matching, usage with options, and pre-compiling patterns with the `Minimatch` class, including Unicode-aware Posix character classes.
Never use user-provided input directly as a glob pattern without rigorous sanitization or whitelisting. Consider alternative matching strategies for untrusted inputs that do not rely on RegExp.
Always normalize paths to use forward slashes (`/`) before passing them to minimatch as patterns. For example, use `path.posix.normalize(myPath)` or `myPath.replace(/\\/g, '/')` for pattern construction.
Upgrade your Node.js runtime to a compatible version (18, 20, or >=22) to use minimatch version 10 and above.
For the latest ReDoS mitigations (when available), upgrade to the newest major version of minimatch. Be aware that older versions will not receive such security updates.
Review glob pattern sources. If patterns originate from user input, implement strict sanitization or whitelisting. Avoid using complex patterns with untrusted input.
Ensure all glob patterns consistently use forward slashes (`/`) as path separators, even when running on Windows. Convert any `\` to `/` in the pattern string.
Use a named import for ESM: `import { minimatch } from 'minimatch'`. For CommonJS, use destructuring: `const { minimatch } = require('minimatch')`.No dependency data recorded yet.