1 | "use strict";
|
2 |
|
3 | const Call = Function.prototype.call.bind(Function.prototype.call);
|
4 | const Apply = Function.prototype.call.bind(Function.prototype.apply);
|
5 |
|
6 | const micromatch = require("micromatch");
|
7 |
|
8 | const ArrayMap = Array.prototype.map;
|
9 | const isArray = Array.isArray;
|
10 | const ArraySome = Array.prototype.some;
|
11 |
|
12 | const I = require("immutable");
|
13 | const isList = I.List.isList;
|
14 |
|
15 | module.exports = function toMatcher(...args) {
|
16 | return toFunction(args);
|
17 | };
|
18 |
|
19 | function toFunction(aMatch) {
|
20 | if (isArray(aMatch)) {
|
21 | const asFunctions = Call(ArrayMap, aMatch, toFunction);
|
22 |
|
23 | return aPath => Call(ArraySome, asFunctions, aMatch => aMatch(aPath));
|
24 | }
|
25 |
|
26 | if (isList(aMatch)) {
|
27 | const asFunctions = aMatch.map(toFunction);
|
28 |
|
29 | return aPath => asFunctions.some(aMatch => aMatch(aPath));
|
30 | }
|
31 |
|
32 | if (typeof aMatch === "string") {
|
33 | const matcher = new micromatch.matcher(aMatch);
|
34 |
|
35 | return aPath => matcher(aPath);
|
36 | }
|
37 |
|
38 | if (typeof aMatch === "function") return aMatch;
|
39 |
|
40 | return () => false;
|
41 | } |
\ | No newline at end of file |