-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (79 loc) · 1.65 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
68
69
70
71
72
73
74
75
76
77
78
79
let dictionary = {
"a": "ᔑ",
"b": "ʖ",
"c": "ᓵ",
"d": "↸",
"e": "ᒷ",
"f": "⎓",
"g": "⊣",
"h": "⍑",
"i": "╎",
"j": "⋮",
"k": "ꖌ",
"l": "ꖎ",
"m": "ᒲ",
"n": "リ",
"o": "𝙹",
"p": "!¡",
"q": "ᑑ",
"r": "∷",
"s": "ᓭ",
"t": "ℸ",
"u": "⚍",
"v": "⍊",
"w": "∴",
"x": "/",
"y": "||",
"z": "⨅",
" ": " ",
};
let reverse_dictionary = {
"ᔑ": "a",
"ʖ": "b",
"ᓵ": "c",
"↸": "d",
"ᒷ": "e",
"⎓": "f",
"⊣": "g",
"⍑": "h",
"╎": "i",
"⋮": "j",
"ꖌ": "k",
"ꖎ": "l",
"ᒲ": "m",
"リ": "n",
"𝙹": "o",
"!¡": "p",
"ᑑ": "q",
"∷": "r",
"ᓭ": "s",
"ℸ": "t",
"⚍": "u",
"⍊": "v",
"∴": "w",
"/": "x",
"||": "y",
"⨅": "z",
" ": " ",
}
/**
*
* @param {string} text Text to be translated.
* @param {boolean} reverse Wether or not the inputted text is Enchantment table or english.
* @returns {string} Output (Text or Enchantment Table)
*/
function translate(text, reverse) {
var translatedText = [...text.toLowerCase()].map((letter, i, arr) => {
(reverse) ? ((letter == "|" && arr[i + 1] == "|") ? (letter = "||", arr.splice(i + 1, 1)) : letter = letter) : letter = letter;
(reverse) ? ((letter == "!" && arr[i + 1] == "¡") ? (letter = "!¡", arr.splice(i + 1, 1)) : letter = letter) : letter = letter;
var translatedLetter = (reverse) ? reverse_dictionary[letter] : dictionary[letter];
(translatedLetter === undefined) ? translatedText += letter: translatedText += translatedLetter;
return translatedLetter;
}).join("");
return translatedText;
}
module.exports = {
translate: translate,
dictionary: dictionary,
reverse_dictionary: reverse_dictionary,
};