-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.js
68 lines (66 loc) · 3.16 KB
/
encoder.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
exports.encode = function(fel, to)
{
const table = [
//src code ipa ipa-unicode xsampa
[ 'ae', 'æ', 'ɛɪ', '\u025B\u026A', 'EI' ],
[ 'ah', 'à', 'ɐ̆', '\u0250\u0306', '6_X' ],
[ 'ai', 'â', 'aɪ', '\u0061\u026A', 'aI' ],
[ 'ch', 'C', 'tʃ', '\u0074\u0283', 'tS' ],
[ 'fh', 'F', 'v', '\u0076', 'v' ],
[ 'gr', 'G', 'ɡ͡ʀ', '\u0261\u0361\u0280', 'g-\\R\\' ],
[ 'hr', 'H', 'h͡ɾ', '\u0068\u0361\u027E', 'h-\\4' ],
[ 'ia', 'Á', 'ɪ̆ɐ', '\u026A\u0306\u0250', 'I_X6' ],
[ 'ie', 'É', 'i', '\u0069', 'i' ],
[ 'kh', 'K', 'k', '\u006B', 'k' ],
[ 'mr', 'M', 'm͡ɾ', '\u006D\u0361\u027E', 'm-\\4' ],
[ 'rh', 'R', 'r', '\u0072', 'r' ],
[ 'th', 'þ', 'ɸ', '\u0278', 'T' ],
[ 'a', 'a', 'ɐ', '\u0250', '6' ],
[ 'b', 'b', 'b', '\u0062', 'b' ],
[ 'd', 'd', 'd', '\u0064', 'd' ],
[ 'e', 'e', 'ə', '\u0259', '@' ],
[ 'f', 'f', 'f', '\u0066', 'f' ],
[ 'h', 'h', 'h', '\u0068', 'h' ],
[ 'i', 'i', 'ɪ', '\u026A', 'I' ],
[ 'k', 'k', 'c', '\u0063', 'c' ],
[ 'l', 'l', 'l', '\u006C', 'l' ],
[ 'm', 'm', 'm', '\u006D', 'm' ],
[ 'n', 'n', 'n', '\u006E', 'n' ],
[ 'o', 'o', 'o', '\u006F', 'o' ],
[ 'p', 'p', 'p', '\u0070', 'p' ],
[ 'r', 'r', 'ɾ', '\u027E', '4' ],
[ 's', 's', 's', '\u0073', 's' ],
[ 't', 't', 't', '\u0074', 't' ],
[ 'u', 'u', 'u', 'u', 'u' ],
[ 'v', 'v', 'β', '\u03B2', 'B' ],
[ 'w', 'w', 'ʋ', '\u028B', 'v\\' ],
[ '\'', '' , '', '', '' ],
[ '-', '' , '.', '.', '.' ],
];
var ret = '';
if (to == 2) ret = '<';
else if (to == 3) ret = '<';
while (fel.length)
{
var found = false;
for (var i = 0; i < table.length; i++)
{
var r = table[i];
if (fel.startsWith(r[0]))
{
fel = fel.slice(r[0].length);
ret += r[to];
found = true;
break;
}
}
if (!found)
{
ret += fel[0];
fel = fel.slice(1);
}
}
if (to == 2) ret += '>';
else if (to == 3) ret += '>';
return ret;
}