Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial option #141

Open
SuperchupuDev opened this issue Jan 29, 2025 · 0 comments
Open

Add partial option #141

SuperchupuDev opened this issue Jan 29, 2025 · 0 comments

Comments

@SuperchupuDev
Copy link

SuperchupuDev commented Jan 29, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant