-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathworker.js
59 lines (59 loc) · 1.73 KB
/
worker.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
// Generated by LiveScript 1.6.0
(function(){
var worker, lenToRegex, lens, LTMRegexes, lang, fs, pre2;
worker = require('worker');
lenToRegex = {};
lens = [];
LTMRegexes = [];
lang = process.env.lang || process.argv.filter((function(it){
return it === 'a' || it === 't' || it === 'h' || it === 'c';
}))[0];
fs = require('fs');
pre2 = JSON.parse(fs.readFileSync(lang + "/lenToRegex.json"));
init();
worker.dedicated({
proc: proc
});
function init(){
var len, i$, len$, results$ = [];
lenToRegex = pre2.lenToRegex;
lens = [];
for (len in lenToRegex) {
lens.push(len);
lenToRegex[len] = new RegExp(lenToRegex[len], 'g');
}
lens.sort(function(a, b){
return b - a;
});
for (i$ = 0, len$ = lens.length; i$ < len$; ++i$) {
len = lens[i$];
results$.push(LTMRegexes.push(lenToRegex[len]));
}
return results$;
}
function proc(chunk, title, idx){
var i$, ref$, len$, re, esc, codepointsOf, titleCodes, len;
for (i$ = 0, len$ = (ref$ = LTMRegexes).length; i$ < len$; ++i$) {
re = ref$[i$];
chunk = chunk.replace(re, fn$);
}
esc = escape(title);
codepointsOf = function(it){
return it.length - it.split(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g).length + 1;
};
titleCodes = codepointsOf(title);
for (i$ = 0, len$ = (ref$ = lens).length; i$ < len$; ++i$) {
len = ref$[i$];
if (len < titleCodes) {
title = title.replace(lenToRegex[len], fn1$);
}
}
return (idx + " " + esc + " ") + unescape(chunk).replace(/"t":""/, "\"t\":\"" + unescape(title) + "\"");
function fn$(it){
return escape("`" + it + "~");
}
function fn1$(it){
return escape("`" + it + "~");
}
}
}).call(this);