-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·75 lines (66 loc) · 1.76 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
#!/usr/bin/env node
import commander from "commander";
import fs from "fs";
import readline from "readline";
import { convertLine } from "./src/pengim.js";
commander
.version("1.0.0", "-v, --version")
.description("Convert between Teochew romanization systems")
.usage("[OPTIONS]...")
.option("-i, --input <path>", "Path to file containing input text to convert")
.option(
"-f, --from <name>",
"Scheme to convert from: puj, gdpi, ggn, dieghv, fielde",
"puj",
)
.option(
"-t, --to <name>",
"Scheme to convert to: puj, gdpi, ggn, dieghv, fielde",
"gdpi",
)
.option(
"-s, --superscript",
"Superscript tone numbers (gdpi, ggn, dieghv only)",
)
.option("-d, --debug", "Print Syllable object")
.parse(process.argv);
const options = commander.opts();
const systems = ["puj", "gdpi", "ggn", "dieghv", "fielde"];
// Main ----------------------------------------------------------------------
if (!systems.includes(options.from)) {
console.error("Unrecognized input format");
console.error();
commander.help();
}
if (!systems.includes(options.to)) {
console.error("Unrecognized output format");
console.error();
commander.help();
}
async function processLine(input) {
try {
const filestream = fs.createReadStream(input);
const rl = readline.createInterface({
input: filestream,
crlfDelay: Infinity,
});
for await (const line of rl) {
let out = "";
out = convertLine(
line,
options.from,
options.to,
options.superscript,
"[",
"]",
options.debug,
);
console.log(out);
}
} catch (err) {
console.error("Invalid input or no input file specified");
console.error();
commander.help();
}
}
processLine(options.input);