@zwa73/utils 1.0.161 → 1.0.163
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/UtilClass.js +1 -1
- package/dist/UtilFileTools.d.ts +5 -2
- package/dist/UtilFileTools.js +3 -2
- package/dist/UtilFunctions.d.ts +5 -2
- package/dist/UtilFunctions.js +6 -4
- package/package.json +1 -1
- package/src/UtilClass.ts +1 -1
- package/src/UtilFileTools.ts +5 -2
- package/src/UtilFunctions.ts +8 -4
package/dist/UtilClass.js
CHANGED
package/dist/UtilFileTools.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ type LoadJsonFileOpt<T> = Partial<{
|
|
|
36
36
|
type WriteJsonFileOpt = Partial<{
|
|
37
37
|
/**使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
|
|
38
38
|
compress: boolean;
|
|
39
|
+
/**紧凑风格 压缩阈值 默认100 */
|
|
40
|
+
compressThreshold: number;
|
|
39
41
|
/**不自动修改扩展名为json */
|
|
40
42
|
forceExt: boolean;
|
|
41
43
|
}>;
|
|
@@ -118,8 +120,9 @@ export declare namespace UtilFT {
|
|
|
118
120
|
* @param filePath - 文件路径
|
|
119
121
|
* @param token - 所要写入的JToken
|
|
120
122
|
* @param opt - 可选参数
|
|
121
|
-
* @param opt.compress
|
|
122
|
-
* @param opt.forceExt
|
|
123
|
+
* @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
|
|
124
|
+
* @param opt.forceExt - 不自动修改扩展名为json
|
|
125
|
+
* @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
|
|
123
126
|
*/
|
|
124
127
|
function writeJSONFile(filePath: string, token: JToken, opt?: WriteJsonFileOpt): Promise<void>;
|
|
125
128
|
/**保证路径为某个风格
|
package/dist/UtilFileTools.js
CHANGED
|
@@ -181,8 +181,9 @@ var UtilFT;
|
|
|
181
181
|
* @param filePath - 文件路径
|
|
182
182
|
* @param token - 所要写入的JToken
|
|
183
183
|
* @param opt - 可选参数
|
|
184
|
-
* @param opt.compress
|
|
185
|
-
* @param opt.forceExt
|
|
184
|
+
* @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
|
|
185
|
+
* @param opt.forceExt - 不自动修改扩展名为json
|
|
186
|
+
* @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
|
|
186
187
|
*/
|
|
187
188
|
async function writeJSONFile(filePath, token, opt) {
|
|
188
189
|
const str = UtilFunctions_1.UtilFunc.stringifyJToken(token, opt);
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ type ExecOpt = Partial<{
|
|
|
14
14
|
type StringifyOpt = Partial<{
|
|
15
15
|
/**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
|
|
16
16
|
compress: boolean;
|
|
17
|
+
/**紧凑风格 压缩阈值 默认100 */
|
|
18
|
+
compressThreshold: number;
|
|
17
19
|
/**插入的空格 数字为空格数量 默认为制表符\t */
|
|
18
20
|
space: string | number | null | undefined;
|
|
19
21
|
}>;
|
|
@@ -134,8 +136,9 @@ export declare class UtilFunc {
|
|
|
134
136
|
/**将JToken转换为字符串
|
|
135
137
|
* @param token - 待转换的Token
|
|
136
138
|
* @param opt - 可选参数
|
|
137
|
-
* @param opt.space
|
|
138
|
-
* @param opt.compress
|
|
139
|
+
* @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
|
|
140
|
+
* @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
|
|
141
|
+
* @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
|
|
139
142
|
* @returns 转换完成的字符串
|
|
140
143
|
*/
|
|
141
144
|
static stringifyJToken(token: JToken | IJData, opt?: StringifyOpt): string;
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -381,15 +381,17 @@ class UtilFunc {
|
|
|
381
381
|
/**将JToken转换为字符串
|
|
382
382
|
* @param token - 待转换的Token
|
|
383
383
|
* @param opt - 可选参数
|
|
384
|
-
* @param opt.space
|
|
385
|
-
* @param opt.compress
|
|
384
|
+
* @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
|
|
385
|
+
* @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
|
|
386
|
+
* @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
|
|
386
387
|
* @returns 转换完成的字符串
|
|
387
388
|
*/
|
|
388
389
|
static stringifyJToken(token, opt) {
|
|
389
390
|
opt ??= {};
|
|
390
|
-
let { compress, space } = opt;
|
|
391
|
+
let { compress, space, compressThreshold } = opt;
|
|
391
392
|
space ??= "\t";
|
|
392
393
|
space = space === null ? undefined : space;
|
|
394
|
+
compressThreshold ??= 100;
|
|
393
395
|
if (!compress)
|
|
394
396
|
return JSON.stringify(token, null, space);
|
|
395
397
|
const ec = '\uF121\uF122\uF123';
|
|
@@ -400,7 +402,7 @@ class UtilFunc {
|
|
|
400
402
|
const str = JSON.stringify(value);
|
|
401
403
|
if (typeof str != 'string')
|
|
402
404
|
return value;
|
|
403
|
-
if (str.length <=
|
|
405
|
+
if (str.length <= compressThreshold)
|
|
404
406
|
return `${ec}${str}${ec}`;
|
|
405
407
|
return value;
|
|
406
408
|
};
|
package/package.json
CHANGED
package/src/UtilClass.ts
CHANGED
|
@@ -109,7 +109,7 @@ export class Stream<T> implements Iterable<T>{
|
|
|
109
109
|
*/
|
|
110
110
|
each(operation: StreamOperation<T, void>): Stream<T> {
|
|
111
111
|
const opera = async (item: T) => {
|
|
112
|
-
operation(item);
|
|
112
|
+
await operation(item);
|
|
113
113
|
return item;
|
|
114
114
|
};
|
|
115
115
|
return this.trans(opera);;
|
package/src/UtilFileTools.ts
CHANGED
|
@@ -48,6 +48,8 @@ type LoadJsonFileOpt<T> = Partial<{
|
|
|
48
48
|
type WriteJsonFileOpt = Partial<{
|
|
49
49
|
/**使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
|
|
50
50
|
compress:boolean;
|
|
51
|
+
/**紧凑风格 压缩阈值 默认100 */
|
|
52
|
+
compressThreshold:number;
|
|
51
53
|
/**不自动修改扩展名为json */
|
|
52
54
|
forceExt:boolean;
|
|
53
55
|
}>
|
|
@@ -234,8 +236,9 @@ export async function loadJSONFile<T extends JToken>(filePath: string,opt?:LoadJ
|
|
|
234
236
|
* @param filePath - 文件路径
|
|
235
237
|
* @param token - 所要写入的JToken
|
|
236
238
|
* @param opt - 可选参数
|
|
237
|
-
* @param opt.compress
|
|
238
|
-
* @param opt.forceExt
|
|
239
|
+
* @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
|
|
240
|
+
* @param opt.forceExt - 不自动修改扩展名为json
|
|
241
|
+
* @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
|
|
239
242
|
*/
|
|
240
243
|
export async function writeJSONFile(
|
|
241
244
|
filePath: string,
|
package/src/UtilFunctions.ts
CHANGED
|
@@ -24,6 +24,8 @@ type ExecOpt = Partial<{
|
|
|
24
24
|
type StringifyOpt = Partial<{
|
|
25
25
|
/**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
|
|
26
26
|
compress:boolean;
|
|
27
|
+
/**紧凑风格 压缩阈值 默认100 */
|
|
28
|
+
compressThreshold:number;
|
|
27
29
|
/**插入的空格 数字为空格数量 默认为制表符\t */
|
|
28
30
|
space:string|number|null|undefined;
|
|
29
31
|
}>
|
|
@@ -447,15 +449,17 @@ static mapEntries<T extends AnyRecord>
|
|
|
447
449
|
/**将JToken转换为字符串
|
|
448
450
|
* @param token - 待转换的Token
|
|
449
451
|
* @param opt - 可选参数
|
|
450
|
-
* @param opt.space
|
|
451
|
-
* @param opt.compress
|
|
452
|
+
* @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
|
|
453
|
+
* @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
|
|
454
|
+
* @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
|
|
452
455
|
* @returns 转换完成的字符串
|
|
453
456
|
*/
|
|
454
457
|
static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
|
|
455
458
|
opt ??= {};
|
|
456
|
-
let {compress,space} = opt;
|
|
459
|
+
let {compress,space,compressThreshold} = opt;
|
|
457
460
|
space ??="\t";
|
|
458
461
|
space = space===null ? undefined : space;
|
|
462
|
+
compressThreshold ??= 100;
|
|
459
463
|
|
|
460
464
|
if(!compress) return JSON.stringify(token,null,space);
|
|
461
465
|
|
|
@@ -468,7 +472,7 @@ static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
|
|
|
468
472
|
return `${ec}${JSON.stringify(value)}${ec}`;
|
|
469
473
|
const str = JSON.stringify(value);
|
|
470
474
|
if(typeof str!='string') return value;
|
|
471
|
-
if(str.length<=
|
|
475
|
+
if(str.length<=compressThreshold) return `${ec}${str}${ec}`;
|
|
472
476
|
return value;
|
|
473
477
|
}
|
|
474
478
|
|