-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcli.js
52 lines (44 loc) · 1.46 KB
/
cli.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
import { readFileSync } from "fs";
import { Jomini } from "jomini";
const args = process.argv.slice(2);
if (args.length !== 1) {
console.info("expected one argument for the file path");
process.exit(1);
}
console.time("read file");
const buffer = readFileSync(args[0]);
console.timeLog("read file");
(async function () {
console.time("initialize jomini");
const parser = await Jomini.initialize();
console.timeLog("initialize jomini");
console.time("initialize jomini2");
const parser2 = await Jomini.initialize();
console.timeLog("initialize jomini2");
console.time("parse text");
parser.parseText(buffer, { encoding: "windows1252" }, (_) => null);
console.timeLog("parse text");
console.time("parse text whole");
parser.parseText(buffer, { encoding: "windows1252" });
console.timeLog("parse text whole");
console.time("parse text at");
const { player, prestige } = parser.parseText(
buffer,
{ encoding: "windows1252" },
(query) => {
const player = query.at("/player");
const prestige = query.at(`/countries/${player}/prestige`);
return { player, prestige };
}
);
console.log(`player: ${player} | prestige: ${prestige}`);
console.timeLog("parse text at");
console.time("parse text json");
const out = parser.parseText(buffer, { encoding: "windows1252" }, (query) =>
query.json()
);
console.timeLog("parse text json");
console.time("parse json");
JSON.parse(out);
console.timeLog("parse json");
})();