forked from bunkat/pseudoloc
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pseudoloc.js
108 lines (108 loc) · 3.98 KB
/
pseudoloc.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
pseudoloc = function() {
var pseudoloc = {
version: "1.1.0"
};
pseudoloc.option = {};
pseudoloc.reset = function() {
pseudoloc.option = {
prepend: "[!",
append: "!]",
delimiter: "%",
startDelimiter: "",
endDelimiter: "",
extend: 0,
override: undefined
};
};
pseudoloc.reset();
pseudoloc.table = {
A: String.fromCharCode(192, 193, 194, 195, 196, 197, 256, 258, 260, 506, 512, 514),
a: String.fromCharCode(224, 225, 226, 227, 228, 229, 257, 259, 261, 507, 513, 515),
B: String.fromCharCode(223, 385, 579, 665),
b: String.fromCharCode(384, 386, 387, 388, 389, 595),
C: String.fromCharCode(262, 264, 266, 268),
c: String.fromCharCode(263, 265, 267, 269),
D: String.fromCharCode(270, 272, 393, 394),
d: String.fromCharCode(271, 273),
E: String.fromCharCode(274, 276, 278, 280, 282, 516, 518),
e: String.fromCharCode(275, 277, 279, 281, 283, 517, 519),
F: String.fromCharCode(401),
f: String.fromCharCode(402),
G: String.fromCharCode(284, 286, 288, 290),
g: String.fromCharCode(285, 287, 289, 291),
H: String.fromCharCode(292, 294),
h: String.fromCharCode(293, 295),
I: String.fromCharCode(296, 298, 300, 302, 304),
i: String.fromCharCode(297, 299, 301, 303, 305),
J: String.fromCharCode(309),
j: String.fromCharCode(308),
K: String.fromCharCode(310, 408),
k: String.fromCharCode(311, 312, 409),
L: String.fromCharCode(313, 315, 317, 319, 321),
l: String.fromCharCode(314, 316, 318, 320, 322),
N: String.fromCharCode(323, 325, 327, 330, 413),
n: String.fromCharCode(324, 326, 328, 329, 331, 414),
O: String.fromCharCode(332, 334, 336, 416),
o: String.fromCharCode(333, 335, 337, 417),
P: String.fromCharCode(420),
p: String.fromCharCode(421, 447),
Q: String.fromCharCode(490, 492),
q: String.fromCharCode(491, 493, 587),
R: String.fromCharCode(340, 342, 344, 422),
r: String.fromCharCode(341, 343, 345),
S: String.fromCharCode(346, 348, 350, 352),
s: String.fromCharCode(347, 349, 351, 353),
T: String.fromCharCode(354, 356, 358),
t: String.fromCharCode(355, 357, 359),
U: String.fromCharCode(360, 362, 364, 366, 368, 370),
u: String.fromCharCode(361, 363, 365, 367, 369, 371),
W: String.fromCharCode(372),
w: String.fromCharCode(373),
Y: String.fromCharCode(374, 376, 435, 562, 590),
y: String.fromCharCode(375, 436, 563, 591),
Z: String.fromCharCode(377, 379, 381, 437),
z: String.fromCharCode(378, 380, 382, 438)
};
pseudoloc.padStr = " one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty";
pseudoloc.pad = function(str, percent) {
var padStr = pseudoloc.padStr;
var len = Math.floor(str.length * percent) - pseudoloc.option.prepend.length - pseudoloc.option.append.length, pStr = str;
while (padStr.length < len) {
padStr += padStr;
}
if (len > 0) {
pStr += padStr.substr(0, len);
}
return pStr;
};
pseudoloc.str = function(str) {
var opts = pseudoloc.option, startdelim = opts.startDelimiter || opts.delimiter, enddelim = opts.endDelimiter || opts.delimiter, re = new RegExp(startdelim + "\\s*[\\w\\.\\s*]+\\s*" + enddelim, "g"), m, tokens = [], i = 0, tokenIdx = 0, result = "", c, pc;
str = pseudoloc.pad(str, opts.extend);
while (m = re.exec(str)) {
tokens.push(m);
}
var token = tokens[tokenIdx++] || {
index: -1
};
while (i < str.length) {
if (token.index === i) {
result += token[0];
i += token[0].length;
token = tokens[tokenIdx++] || {
index: -1
};
continue;
}
c = opts.override !== undefined ? opts.override : str[i];
pc = pseudoloc.table[c];
if (pc) {
var diacriticalIndex = str.length % pc.length;
c = pc[diacriticalIndex];
}
result += c;
i++;
}
return opts.prepend + result + opts.append;
};
return pseudoloc;
}();