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

What is the difference between matcher and filter? #40

Closed
callumlocke opened this issue Sep 23, 2015 · 7 comments
Closed

What is the difference between matcher and filter? #40

callumlocke opened this issue Sep 23, 2015 · 7 comments

Comments

@callumlocke
Copy link

This might be a documentation issue, or maybe I'm being stupid.

The readme says that .matcher(pattern) gets you a function that you can use to match paths. I'm assuming this means it returns true/false, in which case it sounds like it could be used as an array filter function.

But then there seems to be another method for this exact purpose, .filter(): "Returns a function that can be passed to Array#filter()." I don't get it. Can't the returned function from .matcher be used in this way?

What's the difference?

@es128
Copy link
Member

es128 commented Sep 23, 2015

I can't speak to why both needed to be provided in the API, but here's the difference as far as I can tell:

filter works with one or more glob patterns.

matcher works with one criterion (not an array) and allows regexes and functions as well as glob patterns as the input.

@jonschlinkert
Copy link
Member

Yeah, the differences that @es128 pointed out are correct, but I've thought about removing filter. Maybe we can allow matcher to handle multiple patterns, and get rid of filter next time we make major changes

@callumlocke
Copy link
Author

Maybe we can allow matcher to handle multiple patterns, and get rid of filter next time we make major changes

That sounds good, less confusing.

In the mean time, do I understand correctly that mm.filter(x)(filename) should always work identically to mm(filenames, x), no matter what type x is?

@jonschlinkert
Copy link
Member

What's the use case? might be easier to give good feedback based on what you're trying to accomplish.

@callumlocke
Copy link
Author

The mm() function works like this:

Negation patterns:
Behavior;

  • when the pattern is a string, minimatch behavior is used, so patterns are inclusive by default.
  • when an array of patterns is passed, multimatch behavior is used, so patterns are exclusive by default

Does the function I get back from mm.filter(x) have that same behaviour (i.e. it can either be inclusive or exclusive, depending on whether x is an array or a string)?

@jonschlinkert
Copy link
Member

can [filter] either be inclusive or exclusive, depending on whether x is an array or a string)?

it should, yes. see these unit tests for examples

@jonschlinkert
Copy link
Member

closing since it's not technically an issue. feel free to continue the conversation or open a new issue if a new topic pops up

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

3 participants