-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChangeToJson.js
42 lines (35 loc) · 1.29 KB
/
ChangeToJson.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
/*
Lang轉換為Json格式,由https://gist.github.com/ChAoSUnItY/31c147efd2391b653b8cc12da9699b43修改而成,特別感謝3X0DUS - ChAoS#6969編寫此function。
*/
const fs = require("fs");
const readline = require("readline");
async function LangToJson(path) {
const fileStream = fs.createReadStream(path);
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
let obj = {}, last_key = null
for await (const line of rl) {
if (line.startsWith("#") || line.startsWith("//") || line.startsWith("!")) {
continue;
} else if (line.indexOf("=") === -1) {
if (last_key === null) continue
if (line === "") continue
obj[last_key] += `\n${line}`
} else if (line.indexOf("=") !== -1) {
if (line.split("=").length === 2) {
let kv = line.split("=")
last_key = kv[0]
obj[kv[0]] = kv[1].trimStart()
} else {
if (last_key === null) continue
obj[last_key] += `\n${line}`
}
}
}
fs.writeFileSync("./data/Json.json", JSON.stringify(obj, null, 4));
console.log("已經將轉化後內容儲存");
return String(obj);
}
LangToJson("./data/Lang.lang");