-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (45 loc) · 1.44 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module.exports = mlgproxy;
function mlgproxy(object, options = {}) {
const handler = {
get: function(target, prop) {
let newName = prop.toString();
if (options.replace && typeof options.replace === "object") {
for (const key in options.replace) {
try {
newName = newName.replace(new RegExp(key, 'g'), options.replace[
key]);
} catch (e) {
console.log("Please use a valid regex");
}
}
}
newName = newName.replace(/0/g, "o").replace(/3/g, "e")
.replace(/4/g, "a").replace(/8/g, "ate")
.replace(
/(LO+L|RE+KT)/gi, "");
if (typeof target[newName] === "object") {
return mlgproxy(target[newName], options);
}
return target[newName];
},
set: function(target, prop, value) {
let newName = prop.toString();
if (options.replace && typeof options.replace === "object") {
for (const key in options.replace) {
try {
newName = newName.replace(new RegExp(key, 'g'), options.replace[
key]);
} catch (e) {
console.log("Please use a valid regex");
}
}
}
newName = newName.replace(/0/g, "o").replace(/3/g, "e")
.replace(/4/g, "a").replace(/8/g, "ate")
.replace(
/(LO+L|RE+KT)/gi, "");
return target[newName] = value;
}
};
return new Proxy(object, handler);
};