-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.js
91 lines (91 loc) · 2.76 KB
/
converter.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
function updateOutput() {
let inputElement = document.getElementById("input");
let outputElement = document.getElementById("output");
let trimOutputElement = document.getElementById("trim-output");
outputElement.readOnly = false;
let input = inputElement.value;
let output = "";
let alphabet = new RegExp("[A-z]");
let numbers = new RegExp("[0-9]");
for (var i = 0; i < input.length; i++) {
let c = input.charAt(i);
if (alphabet.test(c)) {
output += ":regional_indicator_" + c.toString().toLowerCase() + ": ";
}
else if (numbers.test(c)) {
switch (c) {
case "1":
output += ":one: ";
break;
case "2":
output += ":two: ";
break;
case "3":
output += ":three: ";
break;
case "4":
output += ":four: ";
break;
case "5":
output += ":five: ";
break;
case "6":
output += ":six: ";
break;
case "7":
output += ":seven: ";
break;
case "8":
output += ":eight: ";
break;
case "9":
output += ":nine: ";
break;
case "0":
output += ":zero: ";
break;
}
}
else if (c == " ") {
output += " ";
}
else if (c == "*") {
output += ":asterisk: ";
}
else if (c == "~") {
output += ":wavy_dash: ";
}
else if (c == '-' || c == '–' || c == '—' || c == '−') {
output += ":heavy_minus_sign: ";
}
else if (c == "+") {
output += ":heavy_plus_sign: ";
}
else if (c == "#") {
output += ":hash: ";
}
else if (c == "!") {
output += ":exclamation: ";
}
else if (c == "?") {
output += ":question: ";
}
}
if (trimOutputElement.checked && output.length > 2000) {
output = output.slice(0, 2000);
}
document.getElementById("output").innerHTML = output;
outputElement.readOnly = true;
}
function copyToClipboard() {
let outputElement = document.getElementById("output");
outputElement.select();
try {
var successful = document.execCommand("copy");
var message = successful ? "successful" : "unsuccessful";
alert("Copy " + message);
}
catch (_a) {
alert("Oops, unable to copy. :(");
}
}