-
Notifications
You must be signed in to change notification settings - Fork 1
/
exec.ts
60 lines (56 loc) · 1.44 KB
/
exec.ts
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
#!/usr/bin/env node
import { Braille } from "./braille";
import { HanBraille } from "./hanbraille";
let help: string =
`HanBraille - Hangul Braille Converter
Usage: hanbraille [-a] [-i] [-q] "Some string"
-a print results as Braille ASCII
-i consider isolated vowel 'i' as postpositions, rather than jamo themselves
-q consider final 'ieung' as null symbols
`;
let args: string[] = process.argv.slice(2);
if (process.stdin.isTTY && args.length < 1) {
console.log(help);
process.exit(1);
}
let ascii: boolean = false;
let text = '';
let u11bc_null = false;
let u3163_isolate = false;
for (let q of args) {
if (q === '-a') {
ascii = true;
}
else if (q === '-q') {
u11bc_null = true;
}
else if (q === '-i') {
u3163_isolate = true;
}
else if (text === '') {
text = '' + q;
}
else {
text = text.concat(' ', q);
}
}
var hanbraille = new HanBraille(u11bc_null, u3163_isolate);
if (!process.stdin.isTTY) {
process.stdin.setEncoding('utf8');
process.stdin.on('data', (chunk) => {
text = chunk.toString().replace(/\r\n/g, '\n');
})
.on('end', () => {
let out = hanbraille.HangBrai(text);
if (ascii) {
out = hanbraille.BraiUCSToASCII(out);
}
console.log(out);
});
} else {
let out = hanbraille.HangBrai(text);
if (ascii) {
out = hanbraille.BraiUCSToASCII(out);
}
console.log(out);
}