-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (63 loc) · 1.53 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
58
59
60
61
62
63
64
65
66
67
/**
*
* max unicode 65535
*/
function encode(text) {
var i = 0,
u,
length = text.length,
str = '',
encodeStr = '';
while (i !== length) {
//get unicode
u = text[i++].charCodeAt()
//to binary
str = u.toString(2)
// max 65535 => 1111111111111111
if (str.length > 16) {
continue;
}
while (str.length !== 16) {
str = '0' + str;
}
str = str.replace(/\d{2}/g, function(c) {
return {
'00': '\u200b',
'01': '\u200c',
'10': '\u200d',
'11': '\ufeff',
}[c]
});
encodeStr += str;
}
return encodeStr;
}
function deconde(text) {
return text.replace(/......../g, function($) {
return String.fromCharCode(parseInt($.replace(/./g, function($) {
return {
'': '00',
'': '01',
'': '10',
'': '11'
}[$]
}), 2))
})
}
/**
*
*/
exports.encode = encode;
exports.deconde = deconde;
exports.jsEncode = function(js){
return 'Function(\''+ encode(js) +'\'.replace(/......../g, function($) { \
return String.fromCharCode(parseInt($.replace(/./g, function($) {\
return {\
\'\': \'00\',\
\'\': \'01\',\
\'\': \'10\',\
\'\': \'11\'\
}[$]\
}), 2))\
}))()'
}