UNPKG

1.03 kBJavaScriptView Raw
1"use strict";
2
3const Call = Function.prototype.call.bind(Function.prototype.call);
4const Apply = Function.prototype.call.bind(Function.prototype.apply);
5
6const micromatch = require("micromatch");
7
8const ArrayMap = Array.prototype.map;
9const isArray = Array.isArray;
10const ArraySome = Array.prototype.some;
11
12const I = require("immutable");
13const isList = I.List.isList;
14
15module.exports = function toMatcher(...args) {
16 return toFunction(args);
17};
18
19function 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