@zwa73/utils 1.0.154 → 1.0.156

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
+ /**使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
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 - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
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 - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
185
185
  * @param opt.forceExt - 不自动修改扩展名为json
186
186
  */
187
187
  async function writeJSONFile(filePath, token, opt) {
@@ -1,4 +1,4 @@
1
- import { PRecord, AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord } from "./UtilInterfaces";
1
+ import { PRecord, AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord, AllExtends } from "./UtilInterfaces";
2
2
  import { LogLevel } from "./UtilLogger";
3
3
  import { Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
4
4
  declare const HashMethodList: readonly ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
@@ -135,7 +135,7 @@ export declare class UtilFunc {
135
135
  * @param token - 待转换的Token
136
136
  * @param opt - 可选参数
137
137
  * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
138
- * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
138
+ * @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
139
139
  * @returns 转换完成的字符串
140
140
  */
141
141
  static stringifyJToken(token: JToken | IJData, opt?: StringifyOpt): string;
@@ -304,6 +304,6 @@ export declare class UtilFunc {
304
304
  * @param expiry - 缓存的有效期 毫秒 默认为Infinity, 表示缓存永不过期。
305
305
  * @returns 返回一个新的函数,这个函数在调用时会尝试从缓存中获取结果,如果缓存不存在或已过期,就会调用原函数并缓存其结果。
306
306
  */
307
- static memoize<T extends (...args: UnionToIntersection<JToken>[]) => any>(fn: T, expiry?: number): T;
307
+ static memoize<T extends (...args: any[]) => any>(fn: T, expiry?: number): T extends (...args: infer In) => any ? AllExtends<In, JToken> extends true ? T : never : never;
308
308
  }
309
309
  export {};
@@ -382,7 +382,7 @@ class UtilFunc {
382
382
  * @param token - 待转换的Token
383
383
  * @param opt - 可选参数
384
384
  * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
385
- * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
385
+ * @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
386
386
  * @returns 转换完成的字符串
387
387
  */
388
388
  static stringifyJToken(token, opt) {
@@ -48,6 +48,8 @@ export type Literal<L> = ProperSubset<string, L> | ProperSubset<number, L> | Pro
48
48
  * @template L - 目标量
49
49
  */
50
50
  export type LiteralCheck<L> = ProperSubsetCheck<string, L> extends "P" ? true : ProperSubsetCheck<number, L> extends "P" ? true : ProperSubsetCheck<boolean, L> extends "P" ? true : ProperSubsetCheck<symbol, L> extends "P" ? true : ProperSubsetCheck<any[], L> extends "P" ? true : ProperSubsetCheck<Record<any, any>, L> extends "P" ? true : L extends null | undefined ? true : false;
51
+ /**递归判断元组 List 每个元素是否 extends T */
52
+ export type AllExtends<List extends any[], T> = List extends [infer First, ...infer Rest] ? First extends T ? AllExtends<Rest, T> : false : true;
51
53
  /**返回将Mixin分配给Base的结果,相同字段时Mixin覆盖Base */
52
54
  export type AssignObject<Base extends AnyRecord, Mixin extends AnyRecord> = {
53
55
  [P in keyof Mixin | keyof Base]: P extends keyof Mixin ? Mixin[P] : P extends keyof Base ? Base[P] : never;
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.154",
3
+ "version": "1.0.156",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "jest",
8
- "postinstall": "start node ./scripts/postinstall.js",
9
8
  "release": "powershell scripts/release",
10
9
  "compile": "powershell scripts/compile",
11
10
  "watch": "powershell scripts/watch",
@@ -46,7 +46,7 @@ type LoadJsonFileOpt<T> = Partial<{
46
46
 
47
47
  /**json文件写入选项 */
48
48
  type WriteJsonFileOpt = Partial<{
49
- /**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
49
+ /**使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
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 - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
238
238
  * @param opt.forceExt - 不自动修改扩展名为json
239
239
  */
240
240
  export async function writeJSONFile(
@@ -1,5 +1,5 @@
1
1
  import * as crypto from "crypto";
2
- import { PRecord, AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqStat, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord } from "@src/UtilInterfaces";
2
+ import { PRecord, AnyFunc, ComposedClass, ComposedMixinable, ComposedRefMixinable, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Mixinable, Outcome, ReqStat, ReqVerifyFn, ProperSubsetCheck, RefMixinable, UnionToIntersection, Await, AnyRecord, AllExtends } from "@src/UtilInterfaces";
3
3
  import * as cp from "child_process";
4
4
  import { LogLevel, SLogger } from "@src/UtilLogger";
5
5
  import { Completed, Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Terminated, Timeout } from "./UtilSymbol";
@@ -448,7 +448,7 @@ static mapEntries<T extends AnyRecord>
448
448
  * @param token - 待转换的Token
449
449
  * @param opt - 可选参数
450
450
  * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
451
- * @param opt.compress - 使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误
451
+ * @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
452
452
  * @returns 转换完成的字符串
453
453
  */
454
454
  static stringifyJToken(token:JToken|IJData,opt?:StringifyOpt){
@@ -861,7 +861,10 @@ static ivk<T extends ()=>any>(fn:T): ReturnType<T> {
861
861
  * @param expiry - 缓存的有效期 毫秒 默认为Infinity, 表示缓存永不过期。
862
862
  * @returns 返回一个新的函数,这个函数在调用时会尝试从缓存中获取结果,如果缓存不存在或已过期,就会调用原函数并缓存其结果。
863
863
  */
864
- static memoize<T extends (...args:UnionToIntersection<JToken>[])=>any> (fn: T, expiry = Infinity): T {
864
+ static memoize<T extends (...args:any[])=>any> (fn: T, expiry = Infinity):
865
+ T extends (...args:infer In)=>any
866
+ ? AllExtends<In,JToken> extends true ? T : never
867
+ : never {
865
868
  const cache = UtilFunc.cachePool.get(fn) ?? UtilFunc.ivk(()=>{
866
869
  const c = new Map();
867
870
  UtilFunc.cachePool.set(fn, c);
@@ -879,7 +882,7 @@ static memoize<T extends (...args:UnionToIntersection<JToken>[])=>any> (fn: T, e
879
882
  const result = fn(...args);
880
883
  cache.set(key, { result, timestamp: now });
881
884
  return result;
882
- }) as T;
885
+ }) as any;
883
886
  }
884
887
 
885
888
 
@@ -72,6 +72,15 @@ export type LiteralCheck<L> =
72
72
  ProperSubsetCheck<Record<any,any>, L> extends "P" ? true :
73
73
  L extends null | undefined ? true : false;
74
74
 
75
+ /**递归判断元组 List 每个元素是否 extends T */
76
+ export type AllExtends<List extends any[], T> =
77
+ List extends [infer First, ...infer Rest]
78
+ ? First extends T
79
+ ? AllExtends<Rest,T>
80
+ : false
81
+ : true;
82
+
83
+
75
84
  /**返回将Mixin分配给Base的结果,相同字段时Mixin覆盖Base */
76
85
  export type AssignObject<Base extends AnyRecord, Mixin extends AnyRecord> = {
77
86
  [P in keyof Mixin | keyof Base]: P extends keyof Mixin ? Mixin[P] : P extends keyof Base ? Base[P] : never;