Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions docs/modules/micromatch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
description: Modern alternatives to the micromatch package for glob pattern matching
---

# Replacements for `micromatch`

## `path.matchesGlob` (native, since Node 20.17 / 22.5)

[`path.matchesGlob`](https://nodejs.org/api/path.html#pathmatchesglobpath-pattern-options) is built into modern versions of Node. Use it when you only need to test whether a path matches a single glob pattern.

Example:

```ts
import micromatch from 'micromatch' // [!code --]
import path from 'node:path' // [!code ++]

micromatch.isMatch('foo.bar', '*.bar') // [!code --]
path.matchesGlob('foo.bar', '*.bar') // [!code ++]
```

For multiple patterns, test each pattern explicitly:

```ts
const patterns = ['*.js', '*.ts']
const matches = patterns.some((pattern) => path.matchesGlob(file, pattern))
```

## `picomatch`

[`picomatch`](https://github.com/micromatch/picomatch) is the matcher micromatch is built on. It is a strong drop-in for most `isMatch` and list-filtering use cases.

Example:

```ts
import micromatch from 'micromatch' // [!code --]
import picomatch from 'picomatch' // [!code ++]

micromatch.isMatch('foo.bar', '*.bar') // [!code --]
picomatch.isMatch('foo.bar', '*.bar') // [!code ++]
```

For a reusable matcher function:

```ts
const isMatch = picomatch('*.js')
isMatch('a.js') // true
```

## `zeptomatch`

[`zeptomatch`](https://github.com/fabiospampinato/zeptomatch) is a tiny glob matcher with brace expansion, ranges, and negation. Note that its argument order is **glob first, path second**.

Example:

```ts
import micromatch from 'micromatch' // [!code --]
import zeptomatch from 'zeptomatch' // [!code ++]

micromatch.isMatch('foo.bar', '*.bar') // [!code --]
zeptomatch('*.bar', 'foo.bar') // [!code ++]
```

Zeptomatch also supports partial matching for filesystem walks and brace expansion:

```ts
zeptomatch('foo/bar/*.js', 'foo', { partial: true }) // true
zeptomatch('{a,b}.js', 'a.js') // true
zeptomatch('!*.test.js', 'foo.js') // true
```
25 changes: 25 additions & 0 deletions manifests/native.json
Original file line number Diff line number Diff line change
Expand Up @@ -1747,12 +1747,26 @@
"compatKey": "javascript.builtins.parseInt"
}
},
"path.matchesGlob": {
"id": "path.matchesGlob",
"type": "native",
"url": {
"type": "node",
"id": "api/path.html#pathmatchesglobpath-pattern-options"
},
"nodeFeatureId": {"moduleName": "path", "exportName": "matchesGlob"}
},
"path.parse": {
"id": "path.parse",
"type": "native",
"url": {"type": "node", "id": "api/path.html#pathparsepath"},
"nodeFeatureId": {"moduleName": "path", "exportName": "parse"}
},
"picomatch": {
"id": "picomatch",
"type": "documented",
"replacementModule": "picomatch"
},
"process.allowedNodeEnvironmentFlags": {
"id": "process.allowedNodeEnvironmentFlags",
"type": "native",
Expand Down Expand Up @@ -1810,6 +1824,11 @@
"url": {"type": "node", "id": "api/util.html#utilpromisifyoriginal"},
"nodeFeatureId": {"moduleName": "util", "exportName": "promisify"}
},
"zeptomatch": {
"id": "zeptomatch",
"type": "documented",
"replacementModule": "zeptomatch"
},
"zlib.crc32": {
"id": "zlib.crc32",
"type": "native",
Expand Down Expand Up @@ -2602,6 +2621,12 @@
"moduleName": "math.sign",
"replacements": ["Math.sign"]
},
"micromatch": {
"type": "module",
"moduleName": "micromatch",
"replacements": ["path.matchesGlob", "picomatch", "zeptomatch"],
"url": {"type": "e18e", "id": "micromatch"}
},
"native-promise-only": {
"type": "module",
"moduleName": "native-promise-only",
Expand Down