forked from ccagml/leetcode-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnls.ts
97 lines (88 loc) · 2.45 KB
/
nls.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
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
88
89
90
91
92
93
94
95
96
97
import * as fse from "fs-extra";
let result_json = {};
function check_key(object, father: Array<any>) {
let main_join = father.join(".");
if (object["description"]) {
let key = main_join + ".description";
if (result_json[key]) {
console.log("重复", key, object);
}
result_json[key] = object["description"];
object["description"] = `%${key}%`;
}
if (object["title"]) {
let key = main_join + ".title";
if (result_json[key]) {
console.log("重复", key);
}
result_json[key] = object["title"];
object["title"] = `%${key}%`;
}
if (object["name"]) {
let key = main_join + ".name";
if (result_json[key]) {
console.log("重复", key);
}
result_json[key] = object["name"];
object["name"] = `%${key}%`;
}
if (object["label"]) {
let key = main_join + ".label";
if (result_json[key]) {
console.log("重复", key);
}
result_json[key] = object["label"];
object["label"] = `%${key}%`;
}
if (object["enumDescriptions"]) {
let key = main_join + ".enumDescriptions";
if (result_json[key]) {
console.log("重复", key);
}
for (let e_index = 0; e_index < object["enumDescriptions"].length; e_index++) {
let b_key = key + `.${e_index}`;
result_json[b_key] = object["enumDescriptions"][e_index];
}
// object["enumDescriptions"] = `%${key}%`;
}
}
function print_obj(object, father) {
let obj_key = object["command"] || object["id"];
if (obj_key) {
father.push(obj_key);
}
check_key(object, father);
for (const key in object) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
const element = object[key];
father.push(key);
if (Array.isArray(element)) {
print_arr(element, father);
} else if (typeof element == "object") {
print_obj(element, father);
}
father.pop();
}
}
if (obj_key) {
father.pop();
}
}
function print_arr(object, father) {
for (let i = 0; i < object.length; i++) {
const element = object[i];
if (Array.isArray(element)) {
print_arr(element, father);
} else if (typeof element == "object") {
print_obj(element, father);
}
}
}
async function test() {
let temp_data = await fse.readFile("./package.json", "utf8");
let ob = JSON.parse(temp_data);
print_obj(ob, ["main"]);
await fse.writeFile("./nls.json", JSON.stringify(result_json));
await fse.writeFile("./package.json", JSON.stringify(ob));
}
test();