-
-
Notifications
You must be signed in to change notification settings - Fork 69
Description
minimatch
has a partial
option that seems to do a partial match. This is great for optimizations in path traversal libraries. As per minimatch
's docs:
partial
Compare a partial path to a pattern. As long as the parts of the path that
are present are not contradicted by the pattern, it will be treated as a
match. This is useful in applications where you're walking through a
folder structure, and don't yet have the full path, but want to ensure that
you do not walk down paths that can never be a match.For example,
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
I am building a library that would greatly benefit from this functionality, but I also would rather not switch to minimatch
as I greatly value picomatch
's advantages in terms of performance. It also seems like I'm not the first one to suggest this, as someone also opened a feature request in micromatch
(micromatch/micromatch#276).
Many existing libraries that make use of picomatch
(that currently implement this behavior themselves) would also benefit from this, such as fast-glob
: https://github.com/mrmlnc/fast-glob/blob/096a5b620f4224eb692bd8ff2c8de0e634e50d8e/src/providers/matchers/partial.ts