/
index.js
36 lines (34 loc) · 947 Bytes
/
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
let numWords = ['zero','one','two','three','four',
'five','six','seven','eight','nine'];
let charTable = {
"!": 'exclamation',
"?": 'question',
"+": "heavy_plus_sign",
"-": "heavy_minus_sign",
"×": "heavy_multiplication_x",
"*": "asterisk",
"$": "heavy_dollar_sign",
"/": "heavy_division_sign"
};
exports.convert = (input) => {
input = [...input.toLowerCase()];
let finalString = '';
for (let i = 0; i < input.length; i++) {
let rawChar = input[i];
let emojiText = '';
if (rawChar.match(/[a-z]/i)) {
emojiText = `regional_indicator_${rawChar}`;
} else if (rawChar.match(/[0-9]/i)) {
emojiText = `${numWords[parseInt(rawChar)]}`;
} else if (rawChar !== ' ') {
let symbol = charTable[rawChar];
if (!symbol) continue;
emojiText = symbol;
} else {
finalString += ` `;
continue;
}
finalString += `:${emojiText}: `;
}
return finalString.trimEnd()
}