fast-cocos 1.1.21 → 1.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/json/src/index.js +2 -2
- package/dist/utils.js +16 -6
- package/dist/xlsx/src/XlsxParser.js +1 -1
- package/dist/xlsx/template/xlsx.txt +13 -13
- package/package.json +1 -1
package/dist/json/src/index.js
CHANGED
|
@@ -17,8 +17,8 @@ const JsonUtils_1 = require("./JsonUtils");
|
|
|
17
17
|
function main() {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
commander_1.program
|
|
20
|
-
.name("
|
|
21
|
-
.description("
|
|
20
|
+
.name("json")
|
|
21
|
+
.description("json utility")
|
|
22
22
|
.version("1.0.0")
|
|
23
23
|
.requiredOption("-s, --source <source>", "source directory")
|
|
24
24
|
.requiredOption("-o, --output <output>", "output directory")
|
package/dist/utils.js
CHANGED
|
@@ -164,7 +164,7 @@ var utils;
|
|
|
164
164
|
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
165
165
|
}
|
|
166
166
|
if (typeof content != "string") {
|
|
167
|
-
content = JSON.stringify(content
|
|
167
|
+
content = JSON.stringify(content);
|
|
168
168
|
}
|
|
169
169
|
fs_1.default.writeFileSync(filePath, content, { encoding: "utf-8" });
|
|
170
170
|
}
|
|
@@ -228,11 +228,11 @@ var utils;
|
|
|
228
228
|
}
|
|
229
229
|
utils.rmSync = rmSync;
|
|
230
230
|
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
* 字符串格式化
|
|
232
|
+
* @param template
|
|
233
|
+
* @param args
|
|
234
|
+
* @example let str = "my name is {0}, my age is {1}", stringFormat(str,"test",30) => my name is test, my age is 30
|
|
235
|
+
* */
|
|
236
236
|
function stringFormat(template, ...args) {
|
|
237
237
|
if (!template) {
|
|
238
238
|
return "";
|
|
@@ -246,10 +246,20 @@ var utils;
|
|
|
246
246
|
return template;
|
|
247
247
|
}
|
|
248
248
|
utils.stringFormat = stringFormat;
|
|
249
|
+
/**
|
|
250
|
+
* Base64 解码为字符串
|
|
251
|
+
* @param base64 Base64 字符串
|
|
252
|
+
* @returns 解码后的 utf-8 字符串
|
|
253
|
+
*/
|
|
249
254
|
function decodeBase64(base64) {
|
|
250
255
|
return Buffer.from(base64, "base64").toString("utf-8");
|
|
251
256
|
}
|
|
252
257
|
utils.decodeBase64 = decodeBase64;
|
|
258
|
+
/**
|
|
259
|
+
* 字符串编码为 Base64
|
|
260
|
+
* @param str 原始字符串
|
|
261
|
+
* @returns Base64 字符串
|
|
262
|
+
*/
|
|
253
263
|
function encodeBase64(str) {
|
|
254
264
|
return Buffer.from(str).toString("base64");
|
|
255
265
|
}
|
|
@@ -672,7 +672,7 @@ class XlsxParser {
|
|
|
672
672
|
}
|
|
673
673
|
propertyStr += `\n`;
|
|
674
674
|
propertyStr += " ".repeat(4) + `/** ${annotation} */\n`;
|
|
675
|
-
propertyStr += " ".repeat(4) + `public readonly ${filename}: sheet.${filename}
|
|
675
|
+
propertyStr += " ".repeat(4) + `public readonly ${filename}: sheet.${filename} = null!;\n`;
|
|
676
676
|
assignStr += " ".repeat(8) + `(this.${filename} as any) = "${filename}";\n`;
|
|
677
677
|
}
|
|
678
678
|
scriptStr = scriptStr.replace("{0}", propertyStr);
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
/** 数字序列 */
|
|
2
2
|
type BuildNumbers<N extends number, Result extends number[] = []> = Result["length"] extends N
|
|
3
3
|
? never
|
|
4
4
|
: [...Result, Result["length"]] extends [infer _, ...infer Rest]
|
|
5
5
|
? Result["length"] | BuildNumbers<N, [...Result, Result["length"]]>
|
|
6
6
|
: never;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/** 生成 1 到 10 的数字 */
|
|
9
9
|
type NumberRange = Exclude<BuildNumbers<11>, 0>;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/** Excel版本 */
|
|
12
12
|
type XlsxVersion = `v${NumberRange}`;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/** 整数 */
|
|
15
15
|
export type int = number;
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/** 浮点数 */
|
|
18
18
|
export type float = number;
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
/** Excel工作表数据 */
|
|
21
21
|
type XlsxData<T = unknown> = { [key: string]: T };
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/** Excel工作表管理 */
|
|
24
24
|
class Xlsx {
|
|
25
25
|
private static _instance: Xlsx;
|
|
26
26
|
public static get instance(): Xlsx {
|
|
27
27
|
return Xlsx._instance ?? (Xlsx._instance = new Xlsx());
|
|
28
28
|
}
|
|
29
|
-
[key: string]: any;
|
|
29
|
+
// [key: string]: any;
|
|
30
30
|
private readonly sheetToKey: Map<string, string>;
|
|
31
31
|
{0}
|
|
32
32
|
private constructor() {
|
|
@@ -35,7 +35,7 @@ class Xlsx {
|
|
|
35
35
|
const keys = Object.keys(this).filter((it) => it != "sheetToKey");
|
|
36
36
|
const values = Object.values(this);
|
|
37
37
|
for (const value of values) {
|
|
38
|
-
const key = keys.find((key) => this[key] === value);
|
|
38
|
+
const key = keys.find((key) => (this as any)[key] === value);
|
|
39
39
|
key && this.sheetToKey.set(value, key);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -56,24 +56,24 @@ class Xlsx {
|
|
|
56
56
|
public updateSheet<T>(sheetName: string, data: T): void {
|
|
57
57
|
const key = this.sheetToKey.get(sheetName);
|
|
58
58
|
if (!key) {
|
|
59
|
-
this[sheetName] = data;
|
|
59
|
+
(this as any)[sheetName] = data;
|
|
60
60
|
console.warn(`强制更新表【${sheetName}】`);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
if (sheetName.endsWith("KVMap") || (!sheetName.endsWith("VMap") && sheetName.endsWith("Map"))) {
|
|
65
|
-
this[key] = this.toMap(data as { [key: string]: unknown });
|
|
65
|
+
(this as any)[key] = this.toMap(data as { [key: string]: unknown });
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
this[key] = data;
|
|
69
|
+
(this as any)[key] = data;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* 检查没有的配置表
|
|
74
74
|
*/
|
|
75
75
|
public checkNotSheet(): string[] {
|
|
76
|
-
return [...this.sheetToKey.keys()].filter((sheetName) => typeof this[sheetName] == "string");
|
|
76
|
+
return [...this.sheetToKey.keys()].filter((sheetName) => typeof (this as any)[sheetName] == "string");
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
/**
|