-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
43 lines (39 loc) · 992 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*!
* is-match <https://github.com/jonschlinkert/is-match>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var typeOf = require('kind-of');
var deepEqual = require('deep-equal');
var isNumber = require('is-number');
var mm = require('micromatch');
module.exports = function(patterns, options) {
if (isNumber(patterns)) {
return function(str) {
return Number(patterns) === Number(str);
};
}
switch (typeOf(patterns)) {
case 'function':
return patterns;
case 'object':
return function(val) {
return deepEqual(val, patterns);
};
case 'regexp':
return function(str) {
return patterns.test(str);
};
case 'array':
case 'string':
return function(list) {
var len = typeof list === 'string' ? 1 : list.length;
return mm(list, patterns, options).length === len;
};
default: {
throw new TypeError('invalid');
}
}
};