-
-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Feature Request: Testing against multiple patterns #219
Comments
Sure, this is already useful in I'm not sure that The important interfaces are: minimatch(path: string, pattern: string | string[], options: MinimatchOptions): true
class Minimatch {
constructor(pattern: string | string[], options: MinimatchOptions)
}
filter(pattern: string | string[], options: MinimatchOptions = {}): (p: string) => boolean The simple naive approach would be to leverage the fact that minimatch already actually does handle an array of patterns (expanded via Do you have a real use case today where you have a set of patterns and need to ensure that all of them match? |
This wouldn't work for negated patterns though, right? It would be great to be able to pass a list, including negations, and have it checked in order (also applying re-inclusions). For example: const patterns = [
"a/**",
"!a/b/**",
"a/b/c"
];
minimatch("a/b/c", patterns); // true
minimatch("a/b/x", patterns); // false |
At the moment, if developers want to test a path against multiple minimatch patterns at once, there's not really a good option to both maximise correctness and performance - the two options I can see are:
match
with the path on each of them. This is the most correct/compatible method, but comes with a lot of overhead inmatch
related to repeating the same pre-processing of the path into the split path.match
, generate the split path array manually, and then extractthis.set
from each instance and runmatchOne
against the parse results. This is more performant, but requires poking at internals and copying code that may well change in future versions.I'd like to suggest adding an API surface to handle the (I would expect pretty common) case of needing to match paths against multiple patterns at once.
My initial thoughts of what this could look like would be to add either-or-both some simple static helper methods to
Minimatch
, or go all out and create an explicitMinimatchSet
(or similar) class that encapsulates multiple patterns together, and could in the future be potentially expanded to do more optimization among the multiple patterns (e.g. if multiple patterns have a shared prefix, they could be partially combined)Thoughts on potential API shape:
I'm happy to put some time into fleshing this out if it's something you'd like to pursue adding to the library 😄
The text was updated successfully, but these errors were encountered: