-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalbhedtranslate.js
87 lines (69 loc) · 1.46 KB
/
albhedtranslate.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
"use strict"
let albhed = [
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'1234567890',
'!@#$%^&*()',
'_+{}|:"<>?',
'-=[]\\;\',./',
].join('')
let english = [
'epstiwknuvgclrybxhmdofzqaj',
'EPSTIWKNUVGCLRYBXHMDOFZQAJ',
'!@#$%^&*()',
'1234567890',
'-=[]\\;\',./',
'_+{}|:"<>?',
].join('')
function usage() {
console.log(`
Specify either -a (to Al Bhed) or -e (To English) and the input text.
$ node albhedtranslate.js -a "what is this"
fryd ec drec
$ node albhedtranslate.js -e "fryd ec drec"
`)
}
let argv = process.argv
let argc = argv.length
console.log(JSON.stringify([argc, argv]))
if (argc !== 4) {
usage()
return
}
let type = process.argv[2]
let input = process.argv[3]
let isToAlBhed = null
if (type === '-a') {
isToAlBhed = true // english to al bhed
} else if (type === '-e') {
isToAlBhed = false // al bhed to english
} else {
usage()
return
}
function translate(from, to, input) {
let ret = ''
for (let x of input) {
let index = from.indexOf(x)
if (index === -1) {
ret += x;
} else {
let char = to[index]
ret += char
}
}
return ret
}
function e2ab(input) {
return translate(english, albhed, input)
}
function ab2e(input) {
return translate(albhed, english, input)
}
let out = ''
if (isToAlBhed) {
out = e2ab(input)
} else {
out = ab2e(input)
}
console.log(out)