2017-05-28 00:38:50 +02:00
# matcher [](https://travis-ci.org/sindresorhus/matcher)
> Simple [wildcard](https://en.wikipedia.org/wiki/Wildcard_character) matching
Useful when you want to accept loose string input and regexes/globs are too convoluted.
## Install
```
2018-09-20 02:56:13 +02:00
$ npm install matcher
2017-05-28 00:38:50 +02:00
```
## Usage
```js
const matcher = require('matcher');
matcher(['foo', 'bar', 'moo'], ['*oo', '!foo']);
//=> ['moo']
matcher(['foo', 'bar', 'moo'], ['!*oo']);
//=> ['bar']
matcher.isMatch('unicorn', 'uni*');
//=> true
matcher.isMatch('unicorn', '*corn');
//=> true
matcher.isMatch('unicorn', 'un*rn');
//=> true
matcher.isMatch('rainbow', '!unicorn');
//=> true
matcher.isMatch('foo bar baz', 'foo b* b*');
//=> true
matcher.isMatch('unicorn', 'uni\\*');
//=> false
2018-09-20 02:56:13 +02:00
matcher.isMatch('UNICORN', 'UNI*', {caseSensitive: true});
//=> true
matcher.isMatch('UNICORN', 'unicorn', {caseSensitive: true});
//=> false
2017-05-28 00:38:50 +02:00
```
## API
2018-09-20 02:56:13 +02:00
### matcher(inputs, patterns, [options])
2017-05-28 00:38:50 +02:00
Accepts an array of `input` 's and `pattern` 's.
2018-09-20 02:56:13 +02:00
Returns an array of `inputs` filtered based on the `patterns` .
2017-05-28 00:38:50 +02:00
2018-09-20 02:56:13 +02:00
### matcher.isMatch(input, pattern, [options])
2017-05-28 00:38:50 +02:00
Returns a boolean of whether the `input` matches the `pattern` .
#### input
Type: `string`
String to match.
2018-09-20 02:56:13 +02:00
#### options
Type: `Object`
##### caseSensitive
Type: `boolean` < br >
Default: `false`
Treat uppercase and lowercase characters as being the same.
Ensure you use this correctly. For example, files and directories should be matched case-insensitively, while most often, object keys should be matched case-sensitively.
2017-05-28 00:38:50 +02:00
#### pattern
Type: `string`
2018-09-20 02:56:13 +02:00
Use `*` to match zero or more characters. A pattern starting with `!` will be negated.
2017-05-28 00:38:50 +02:00
2017-08-14 05:01:11 +02:00
## Benchmark
```
$ npm run bench
```
2017-05-28 00:38:50 +02:00
## Related
- [multimatch ](https://github.com/sindresorhus/multimatch ) - Extends `minimatch.match()` with support for multiple patterns
## License
2017-08-14 05:01:11 +02:00
MIT © [Sindre Sorhus ](https://sindresorhus.com )