Skip to content

Replacements for micromatch

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

path.matchesGlob 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'
import path from 'node:path'

micromatch.isMatch('foo.bar', '*.bar') 
path.matchesGlob('foo.bar', '*.bar') 

For multiple patterns, test each pattern explicitly:

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

picomatch

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'
import picomatch from 'picomatch'

micromatch.isMatch('foo.bar', '*.bar') 
picomatch.isMatch('foo.bar', '*.bar') 

For a reusable matcher function:

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

zeptomatch

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'
import zeptomatch from 'zeptomatch'

micromatch.isMatch('foo.bar', '*.bar') 
zeptomatch('*.bar', 'foo.bar') 

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

Released under the MIT License. (aba2dbd5)