@zwa73/utils 1.0.135 → 1.0.137

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.
@@ -34,7 +34,7 @@ type LoadJsonFileOpt<T> = Partial<{
34
34
  }>;
35
35
  /**json文件写入选项 */
36
36
  type WriteJsonFileOpt = Partial<{
37
- /**使用紧凑风格 */
37
+ /**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
38
38
  compress: boolean;
39
39
  /**不自动修改扩展名为json */
40
40
  forceExt: boolean;
@@ -118,7 +118,7 @@ export declare namespace UtilFT {
118
118
  * @param filePath - 文件路径
119
119
  * @param token - 所要写入的JToken
120
120
  * @param opt - 可选参数
121
- * @param opt.compress - 使用紧凑风格
121
+ * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
122
122
  * @param opt.forceExt - 不自动修改扩展名为json
123
123
  */
124
124
  function writeJSONFile(filePath: string, token: JToken, opt?: WriteJsonFileOpt): Promise<void>;
@@ -181,7 +181,7 @@ var UtilFT;
181
181
  * @param filePath - 文件路径
182
182
  * @param token - 所要写入的JToken
183
183
  * @param opt - 可选参数
184
- * @param opt.compress - 使用紧凑风格
184
+ * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
185
185
  * @param opt.forceExt - 不自动修改扩展名为json
186
186
  */
187
187
  async function writeJSONFile(filePath, token, opt) {
@@ -10,7 +10,7 @@ type ExecOpt = Partial<{
10
10
  }>;
11
11
  /**序列化选项 */
12
12
  type StringifyOpt = Partial<{
13
- /**使用紧凑风格 */
13
+ /**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
14
14
  compress: boolean;
15
15
  /**插入的空格 数字为空格数量 默认为制表符\t */
16
16
  space: string | number | null | undefined;
@@ -132,7 +132,7 @@ export declare class UtilFunc {
132
132
  * @param token - 待转换的Token
133
133
  * @param opt - 可选参数
134
134
  * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
135
- * @param opt.compress - 使用紧凑风格
135
+ * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
136
136
  * @returns 转换完成的字符串
137
137
  */
138
138
  static stringifyJToken(token: JToken | IJData, opt?: StringifyOpt): string;
@@ -379,7 +379,7 @@ class UtilFunc {
379
379
  * @param token - 待转换的Token
380
380
  * @param opt - 可选参数
381
381
  * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
382
- * @param opt.compress - 使用紧凑风格
382
+ * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
383
383
  * @returns 转换完成的字符串
384
384
  */
385
385
  static stringifyJToken(token, opt) {
@@ -394,13 +394,14 @@ class UtilFunc {
394
394
  typeof item === 'boolean' || item == null))
395
395
  return `@@@${JSON.stringify(value)}@@@`;
396
396
  const str = JSON.stringify(value);
397
+ if (typeof str != 'string')
398
+ return value;
397
399
  if (str.length <= 100)
398
400
  return `@@@${str}@@@`;
399
401
  return value;
400
402
  };
401
403
  return JSON.stringify(token, compressReplacer, space)
402
- .replace(/"@@@(.*?)@@@"/g, `$1`)
403
- .replace(/\\([\\"])/g, '$1');
404
+ .replace(/"@@@(.*?)@@@"/g, (match, p1) => p1.replace(/\\([\\"])/g, '$1'));
404
405
  }
405
406
  /**代办表 用于队列处理等待 */
406
407
  static pendingMap = {};
@@ -211,4 +211,6 @@ export type AnyRecord = Record<Keyable, any>;
211
211
  export type AnnotableTuple<T extends {
212
212
  [K: number]: unknown;
213
213
  }, Tuple extends unknown[] = []> = unknown extends T[Tuple['length']] ? T & Tuple : AnnotableTuple<T, [...Tuple, T[Tuple['length']]]>;
214
+ /**非严格模式下将会判断为false的值, 不包含NaN */
215
+ export type Flasy = false | 0 | -0 | "" | null | undefined;
214
216
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.135",
3
+ "version": "1.0.137",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -46,7 +46,7 @@ type LoadJsonFileOpt<T> = Partial<{
46
46
 
47
47
  /**json文件写入选项 */
48
48
  type WriteJsonFileOpt = Partial<{
49
- /**使用紧凑风格 */
49
+ /**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
50
50
  compress:boolean;
51
51
  /**不自动修改扩展名为json */
52
52
  forceExt:boolean;
@@ -234,7 +234,7 @@ export async function loadJSONFile<T extends JToken>(filePath: string,opt?:LoadJ
234
234
  * @param filePath - 文件路径
235
235
  * @param token - 所要写入的JToken
236
236
  * @param opt - 可选参数
237
- * @param opt.compress - 使用紧凑风格
237
+ * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
238
238
  * @param opt.forceExt - 不自动修改扩展名为json
239
239
  */
240
240
  export async function writeJSONFile(
@@ -20,7 +20,7 @@ type ExecOpt = Partial<{
20
20
 
21
21
  /**序列化选项 */
22
22
  type StringifyOpt = Partial<{
23
- /**使用紧凑风格 */
23
+ /**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
24
24
  compress:boolean;
25
25
  /**插入的空格 数字为空格数量 默认为制表符\t */
26
26
  space:string|number|null|undefined;
@@ -441,7 +441,7 @@ static mapEntries<T extends AnyRecord>
441
441
  * @param token - 待转换的Token
442
442
  * @param opt - 可选参数
443
443
  * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
444
- * @param opt.compress - 使用紧凑风格
444
+ * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
445
445
  * @returns 转换完成的字符串
446
446
  */
447
447
  static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
@@ -458,13 +458,14 @@ static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
458
458
  typeof item === 'boolean' || item == null))
459
459
  return `@@@${JSON.stringify(value)}@@@`;
460
460
  const str = JSON.stringify(value);
461
+ if(typeof str!='string') return value;
461
462
  if(str.length<=100) return `@@@${str}@@@`;
462
463
  return value;
463
464
  }
464
465
 
465
466
  return JSON.stringify(token,compressReplacer,space)
466
- .replace(/"@@@(.*?)@@@"/g,`$1`)
467
- .replace(/\\([\\"])/g, '$1');
467
+ .replace(/"@@@(.*?)@@@"/g, (match, p1) =>
468
+ p1.replace(/\\([\\"])/g, '$1'));
468
469
  }
469
470
 
470
471
  /**代办表 用于队列处理等待 */
@@ -303,4 +303,7 @@ export type AnyRecord = Record<Keyable,any>;
303
303
  export type AnnotableTuple<T extends {[K:number]:unknown},Tuple extends unknown[]=[]> =
304
304
  unknown extends T[Tuple['length']]
305
305
  ? T & Tuple
306
- : AnnotableTuple<T,[...Tuple,T[Tuple['length']]]>;
306
+ : AnnotableTuple<T,[...Tuple,T[Tuple['length']]]>;
307
+
308
+ /**非严格模式下将会判断为false的值, 不包含NaN */
309
+ export type Flasy = false | 0 | -0 | "" | null | undefined;