-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter.js
54 lines (45 loc) · 1.18 KB
/
filter.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
44
45
46
47
48
49
50
51
52
53
54
(function (modules, factory) {
var root = this;
if (typeof define === "function" && define.amd) {
define(modules, factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory.call(root);
} else {
root["mu-track/filter"] = factory.call(root);
}
})([], function () {
var toString = Object.prototype.toString;
return function (filter, index, cb) {
switch (arguments.length) {
case 2:
cb = index;
index = 0;
break;
case 1:
cb = filter;
break;
case 0:
throw new Error("not enough arguments");
}
return function () {
var type = arguments[index];
switch (toString.call(filter)) {
case "[object Function]":
if (filter.apply(this, arguments) !== false) {
break;
}
case "[object RegExp]":
if (filter.test(type) === true) {
break;
}
case "[object String]":
if (type === filter) {
break;
}
default:
return;
}
(toString.call(cb) === "[object Function]" ? cb : cb.handler).apply(this, arguments);
}
}
});