forked from pixeldesu/moduleRaid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoduleraid.js
127 lines (106 loc) · 2.85 KB
/
moduleraid.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* moduleRaid
* https://github.com/pixeldesu/moduleRaid
*
* Copyright pixeldesu and other contributors
* Licensed under the MIT License
* https://github.com/pixeldesu/moduleRaid/blob/master/LICENSE
*/
const moduleRaid = function () {
moduleRaid.mObj = {};
moduleRaid.cArr = [];
moduleRaid.args = [
[[0], [function(e, t, i) {
mCac = i.c;
Object.keys(mCac).forEach (function(mod) {
moduleRaid.mObj[mod] = mCac[mod].exports;
})
moduleRaid.cArr = i.m;
}]],
[[], {'moduleraid': function(e, t, i) {
mCac = i.c;
Object.keys(mCac).forEach (function(mod) {
moduleRaid.mObj[mod] = mCac[mod].exports;
})
moduleRaid.cArr = i.m;
}}, ['moduleraid']]
]
fillModuleArray = function() {
moduleRaid.args.forEach(function (argument) {
webpackJsonp(...argument);
})
if (moduleRaid.mObj.length == 0) {
mEnd = false;
mIter = 0;
if (!webpackJsonp([],[],[mIter])) {
throw Error("Unknown Webpack structure");
}
while (!mEnd) {
try {
moduleRaid.mObj[mIter] = webpackJsonp([],[],[mIter]);
mIter++;
}
catch (err) {
mEnd = true;
}
}
}
}
fillModuleArray()
get = function get (id) {
return moduleRaid.mObj[id]
}
findModule = function findModule (query) {
results = [];
modules = Object.keys(moduleRaid.mObj);
modules.forEach(function(mKey) {
mod = moduleRaid.mObj[mKey];
if (typeof mod !== 'undefined') {
if (typeof mod.default === "object") {
for (key in mod.default) {
if (key == query) results.push(mod);
}
}
for (key in mod) {
if (key == query) results.push(mod);
}
}
})
return results;
}
findFunction = function(query) {
if (moduleRaid.cArr.length == 0) {
throw Error("No module constructors to search through!");
}
results = [];
if (typeof query === "string") {
moduleRaid.cArr.forEach(function (ctor, index) {
if (ctor.toString().includes(query)) {
results.push(moduleRaid.mObj[index]);
}
})
} else if (typeof query === "function") {
modules = Object.keys(moduleRaid.mObj);
modules.forEach(function(mKey, index) {
mod = moduleRaid.mObj[mKey];
if (query(mod)) {
results.push(moduleRaid.mObj[index]);
}
})
} else {
throw new TypeError('findFunction can only find via string and function, ' + (typeof query) + ' was passed');
}
return results;
}
return {
modules: moduleRaid.mObj,
constructors: moduleRaid.cArr,
findModule: findModule,
findFunction: findFunction,
get: get
}
}
if (typeof module === 'object' && module.exports) {
module.exports = moduleRaid;
} else {
window.mR = moduleRaid();
}