@zwa73/utils 1.0.206 → 1.0.208

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.
Files changed (47) hide show
  1. package/dist/QuickExport.d.ts +1 -2
  2. package/dist/QuickExport.js +27 -22
  3. package/dist/UtilClass.d.ts +1 -98
  4. package/dist/UtilClass.js +7 -243
  5. package/dist/UtilDecorators.d.ts +1 -32
  6. package/dist/UtilDecorators.js +15 -225
  7. package/dist/UtilFunctions.d.ts +9 -267
  8. package/dist/UtilFunctions.js +38 -687
  9. package/dist/UtilI18n.js +1 -1
  10. package/dist/UtilInterfaces.d.ts +1 -180
  11. package/dist/UtilInterfaces.js +1 -0
  12. package/dist/UtilLogger.d.ts +19 -20
  13. package/dist/UtilLogger.js +1 -1
  14. package/dist/UtilSymbol.d.ts +1 -40
  15. package/dist/UtilSymbol.js +11 -27
  16. package/dist/index.js +3 -0
  17. package/dist/test/dist/bitcont.d.ts +1 -0
  18. package/dist/test/dist/bitcont.js +153 -0
  19. package/dist/test/dist/error.d.ts +1 -0
  20. package/dist/test/dist/error.js +11 -0
  21. package/dist/test/dist/fptest.d.ts +1 -0
  22. package/dist/test/dist/fptest.js +21 -0
  23. package/dist/test/dist/hbs.d.ts +1 -0
  24. package/dist/test/dist/hbs.js +14 -0
  25. package/dist/test/dist/ip.d.ts +1 -0
  26. package/dist/test/dist/ip.js +107 -0
  27. package/dist/test/dist/llonebot.d.ts +0 -0
  28. package/dist/test/dist/llonebot.js +1 -0
  29. package/dist/test/dist/log.d.ts +1 -0
  30. package/dist/test/dist/log.js +9 -0
  31. package/dist/test/dist/match.d.ts +1 -0
  32. package/dist/test/dist/match.js +19 -0
  33. package/dist/test/dist/pathe.d.ts +1 -0
  34. package/dist/test/dist/pathe.js +7 -0
  35. package/dist/test/dist/queuetest.d.ts +1 -0
  36. package/dist/test/dist/queuetest.js +139 -0
  37. package/dist/test/dist/regtest.d.ts +1 -0
  38. package/dist/test/dist/regtest.js +8 -0
  39. package/dist/test/dist/repeatTest.d.ts +1 -0
  40. package/dist/test/dist/repeatTest.js +120 -0
  41. package/dist/test/dist/stringifytest.d.ts +1 -0
  42. package/dist/test/dist/stringifytest.js +8 -0
  43. package/dist/test/dist/test2.d.ts +1 -0
  44. package/dist/test/dist/test2.js +35 -0
  45. package/dist/test/dist/testStream.d.ts +1 -0
  46. package/dist/test/dist/testStream.js +286 -0
  47. package/package.json +3 -1
@@ -1,227 +1,17 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LogTime = LogTime;
13
- exports.LogTimeAsync = LogTimeAsync;
14
- exports.LogCall = LogCall;
15
- exports.LogCallAsync = LogCallAsync;
16
- exports.LogErr = LogErr;
17
- exports.LogErrAsync = LogErrAsync;
18
- exports.Defer = Defer;
19
- exports.DeferAsync = DeferAsync;
20
- exports.Catch = Catch;
21
- exports.CatchAsync = CatchAsync;
22
- exports.AwaitInited = AwaitInited;
23
- const UtilFunctions_1 = require("./UtilFunctions");
24
- const UtilLogger_1 = require("./UtilLogger");
25
- /**用于打印方法运行时间
26
- * @param flag - 时间标签
27
- * @param suffixUID - 是否尾随uid
28
- */
29
- function LogTime(flag, suffixUID) {
30
- return function (target, propertyKey, descriptor) {
31
- const originalMethod = descriptor.value;
32
- descriptor.value = function (...args) {
33
- const uid = suffixUID ? UtilFunctions_1.UtilFunc.genUUID() : "";
34
- UtilLogger_1.SLogger.time(flag + uid);
35
- let result = originalMethod.apply(this, args);
36
- UtilLogger_1.SLogger.timeEnd(flag + uid);
37
- return result;
38
- };
39
- return descriptor;
40
- };
41
- }
42
- /**用于打印异步方法运行时间
43
- * @param flag - 时间标签
44
- * @param suffixUID - 是否尾随uid
45
- */
46
- function LogTimeAsync(flag, suffixUID) {
47
- return function (target, propertyKey, descriptor) {
48
- const originalMethod = descriptor.value;
49
- descriptor.value = async function (...args) {
50
- const uid = suffixUID ? UtilFunctions_1.UtilFunc.genUUID() : "";
51
- UtilLogger_1.SLogger.time(flag + uid);
52
- let result = await originalMethod.apply(this, args);
53
- UtilLogger_1.SLogger.timeEnd(flag + uid);
54
- return result;
55
- };
56
- return descriptor;
57
- };
58
- }
59
- /**用于打印方法的调用 */
60
- function LogCall() {
61
- return function (target, propertyKey, descriptor) {
62
- const originalMethod = descriptor.value;
63
- descriptor.value = function (...args) {
64
- let result = originalMethod.apply(this, args);
65
- UtilLogger_1.SLogger.info(`调用函数: ${propertyKey}(${args}) => ${result}`);
66
- return result;
67
- };
68
- return descriptor;
69
- };
70
- }
71
- /**用于打印异步方法的调用 */
72
- function LogCallAsync() {
73
- return function (target, propertyKey, descriptor) {
74
- const originalMethod = descriptor.value;
75
- descriptor.value = async function (...args) {
76
- let result = await originalMethod.apply(this, args);
77
- UtilLogger_1.SLogger.info(`调用函数: ${propertyKey}(${args}) => ${result}`);
78
- return result;
79
- };
80
- return descriptor;
81
- };
82
- }
83
- /**用于打印方法的调用 */
84
- function LogErr() {
85
- return function (target, propertyKey, descriptor) {
86
- const originalMethod = descriptor.value;
87
- descriptor.value = function (...args) {
88
- try {
89
- const result = originalMethod.apply(this, args);
90
- return result;
91
- }
92
- catch (err) {
93
- UtilFunctions_1.UtilFunc.throwError(`函数出现错误: ${propertyKey}(${args}): ${err}`, 'warn');
94
- }
95
- };
96
- return descriptor;
97
- };
98
- }
99
- /**用于打印异步方法的调用 */
100
- function LogErrAsync() {
101
- return function (target, propertyKey, descriptor) {
102
- const originalMethod = descriptor.value;
103
- descriptor.value = async function (...args) {
104
- try {
105
- const result = await originalMethod.apply(this, args);
106
- return result;
107
- }
108
- catch (err) {
109
- UtilFunctions_1.UtilFunc.throwError(`函数出现错误: ${propertyKey}(${args}): ${err}`, 'warn');
110
- }
111
- };
112
- return descriptor;
113
- };
114
- }
115
- /**try-finally包装 */
116
- function Defer(deferLogic) {
117
- return function (target, propertyKey, descriptor) {
118
- const originalMethod = descriptor.value;
119
- descriptor.value = function (...args) {
120
- try {
121
- const result = originalMethod.apply(this, args);
122
- return result;
123
- }
124
- finally {
125
- deferLogic(...args);
126
- }
127
- };
128
- return descriptor;
129
- };
130
- }
131
- /**异步的try-finally包装 */
132
- function DeferAsync(deferLogic) {
133
- return function (target, propertyKey, descriptor) {
134
- const originalMethod = descriptor.value;
135
- descriptor.value = async function (...args) {
136
- try {
137
- const result = await originalMethod.apply(this, args);
138
- await deferLogic(...args);
139
- return result;
140
- }
141
- finally {
142
- await deferLogic(...args);
143
- }
144
- };
145
- return descriptor;
146
- };
147
- }
148
- /**try-catch包装 */
149
- function Catch(catchLogic) {
150
- return function (target, propertyKey, descriptor) {
151
- const originalMethod = descriptor.value;
152
- descriptor.value = function (...args) {
153
- try {
154
- const result = originalMethod.apply(this, args);
155
- return result;
156
- }
157
- catch (err) {
158
- //SLogger.warn(`一个函数出现了错误 ${propertyKey}: ${err}`);
159
- return catchLogic(err, ...args);
160
- }
161
- };
162
- return descriptor;
163
- };
164
- }
165
- /**异步的try-catch包装 */
166
- function CatchAsync(catchLogic) {
167
- return function (target, propertyKey, descriptor) {
168
- const originalMethod = descriptor.value;
169
- descriptor.value = async function (...args) {
170
- try {
171
- const result = await originalMethod.apply(this, args);
172
- return result;
173
- }
174
- catch (err) {
175
- //SLogger.warn(`一个函数出现了错误 ${propertyKey}: ${err}`);
176
- return await catchLogic(err, ...args);
177
- }
178
- };
179
- return descriptor;
180
- };
181
- }
182
- /**等待完成init */
183
- function AwaitInited(target, propertyKey, descriptor) {
184
- const originalMethod = descriptor.value;
185
- descriptor.value = async function (...args) {
186
- await this.inited;
187
- return await originalMethod.apply(this, args);
188
- };
189
- return descriptor;
190
- }
191
- function AddNumberDecorator(n) {
192
- return function (target, propertyKey, descriptor) {
193
- const originalMethod = descriptor.value;
194
- descriptor.value = function (num) {
195
- const result = originalMethod.apply(this, [num]);
196
- return result + n;
197
- };
198
- return descriptor;
199
- };
200
- }
201
- class Example {
202
- myMethod(num) {
203
- return num;
204
- }
205
- static async myMethod1(num, ss) {
206
- return 312;
207
- }
208
- }
209
- __decorate([
210
- AddNumberDecorator(10),
211
- __metadata("design:type", Function),
212
- __metadata("design:paramtypes", [Number]),
213
- __metadata("design:returntype", Number)
214
- ], Example.prototype, "myMethod", null);
215
- __decorate([
216
- LogCall(),
217
- Defer((a, b) => null),
218
- CatchAsync(async (a, b) => 123),
219
- __metadata("design:type", Function),
220
- __metadata("design:paramtypes", [Number, String]),
221
- __metadata("design:returntype", Promise)
222
- ], Example, "myMethod1", null);
223
- //let e = new Example();
224
- //e.myMethod1(1,"");
225
- //console.log(123);
226
- //let a = new Example();
227
- //a.myMethod(10);//?
3
+ exports.AwaitInited = exports.CatchAsync = exports.Catch = exports.DeferAsync = exports.Defer = exports.LogErrAsync = exports.LogErr = exports.LogCallAsync = exports.LogCall = exports.LogTimeAsync = exports.LogTime = void 0;
4
+ //#region UtilDecorators转导
5
+ var js_utils_1 = require("@zwa73/js-utils");
6
+ Object.defineProperty(exports, "LogTime", { enumerable: true, get: function () { return js_utils_1.LogTime; } });
7
+ Object.defineProperty(exports, "LogTimeAsync", { enumerable: true, get: function () { return js_utils_1.LogTimeAsync; } });
8
+ Object.defineProperty(exports, "LogCall", { enumerable: true, get: function () { return js_utils_1.LogCall; } });
9
+ Object.defineProperty(exports, "LogCallAsync", { enumerable: true, get: function () { return js_utils_1.LogCallAsync; } });
10
+ Object.defineProperty(exports, "LogErr", { enumerable: true, get: function () { return js_utils_1.LogErr; } });
11
+ Object.defineProperty(exports, "LogErrAsync", { enumerable: true, get: function () { return js_utils_1.LogErrAsync; } });
12
+ Object.defineProperty(exports, "Defer", { enumerable: true, get: function () { return js_utils_1.Defer; } });
13
+ Object.defineProperty(exports, "DeferAsync", { enumerable: true, get: function () { return js_utils_1.DeferAsync; } });
14
+ Object.defineProperty(exports, "Catch", { enumerable: true, get: function () { return js_utils_1.Catch; } });
15
+ Object.defineProperty(exports, "CatchAsync", { enumerable: true, get: function () { return js_utils_1.CatchAsync; } });
16
+ Object.defineProperty(exports, "AwaitInited", { enumerable: true, get: function () { return js_utils_1.AwaitInited; } });
17
+ //#endregion
@@ -1,6 +1,7 @@
1
- import { PRecord, AnyFunc, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Outcome, StatusVerifyFn, ProperSubsetCheck, UnionToIntersection, AnyRecord, AllExtends, SrtSegment, MPromise } from "./UtilInterfaces";
2
- import { LogLevel } from "./UtilLogger";
3
- import { Failed, FailedLike, None, StatusSymbol, Success, SuccessLike, Timeout } from "./UtilSymbol";
1
+ import { LogLevel } from "./UtilInterfaces";
2
+ import { JsFunc } from "@zwa73/js-utils";
3
+ import { ComposedClass } from "@zwa73/modular-mixer";
4
+ export { PromiseRetries, PromiseRetryResult } from "@zwa73/js-utils";
4
5
  declare const HashMethodList: readonly ["md5", "sha1", "sha256", "sha512", "sha3", "blake2", "blake3"];
5
6
  type HashMethod = typeof HashMethodList[number];
6
7
  /**执行选项 */
@@ -12,66 +13,8 @@ type ExecOpt = Partial<{
12
13
  /**工作路径 */
13
14
  cwd: string;
14
15
  }>;
15
- /**序列化选项 */
16
- type StringifyOpt = Partial<{
17
- /**使用紧凑风格 将会用/@@@.+@@@/作为特殊标记, 原始文本内若出现相同格式将会产生错误 */
18
- compress: boolean;
19
- /**紧凑风格 压缩阈值 默认100 */
20
- compressThreshold: number;
21
- /**插入的空格 数字为空格数量 默认为制表符\t */
22
- space: string | number | null | undefined;
23
- }>;
24
- /**Promise重试选项 */
25
- export type PromiseRetries = Partial<{
26
- /**重试次数 默认3*/
27
- count?: number;
28
- /**尝试间隔时间 超过此事件会重新创建新的Promise
29
- * 同时等待新的与旧的Promise 毫秒 默认180_000
30
- */
31
- tryInterval?: number;
32
- /**尝试延迟 重新尝试时会先等待此毫秒数 毫秒 默认0*/
33
- tryDelay?: number;
34
- /**是否使用指数回退 默认false 仅在tryDelay被设置时有效 */
35
- expBackoff?: boolean;
36
- /**指数回退上限值 默认无限*/
37
- expBackoffMax?: number;
38
- }>;
39
- type SuccessOut<T> = Outcome<Success, T>;
40
- type TimeoutOut<T> = Outcome<Timeout, Promise<T>>;
41
- /**完成的重试请求 */
42
- export type PromiseRetryResult<T> = {
43
- completed: T | undefined;
44
- /**还未完成的其他Promise 若是验证失败则会返回undefined */
45
- pending: Promise<T | undefined>[];
46
- };
47
- /**遍历对象的回调函数
48
- * @param key - 字段名
49
- * @param value - 字段值
50
- * @param parent - 父对象
51
- */
52
- type EachFieldCallback = (key: string, value: JToken, parent: JObject) => void;
53
16
  /**常用函数 */
54
- export declare class UtilFunc {
55
- /**获取当前时间戳
56
- * @returns 时间戳
57
- */
58
- static getTime(): number;
59
- /**初始化对象的字段
60
- * 会改变obj
61
- * @param obj - 所要初始化的对象
62
- * @param field - 所要初始化的字段
63
- * @param defaultVal - 默认值
64
- * @returns 最终值
65
- */
66
- static initField<T extends AnyRecord, K extends keyof T>(obj: T, field: K, defaultVal: T[K]): T[K];
67
- /**初始化一个数据对象
68
- * @param obj - 目标对象
69
- * @param checkObj - 用于检测的对象 在对应key缺失时赋予对应值 如果值为函数, 则赋予执行结果 如果结果为 undefined 则不赋值
70
- * @returns 完成初始化的对象
71
- */
72
- static initObject<T extends JObject>(obj: T, checkObj: {
73
- [P in keyof T]: T[P] | (() => void | T[P]);
74
- }): any;
17
+ declare class _UtilFunc {
75
18
  /**生成一串uuid
76
19
  * @returns uuid
77
20
  */
@@ -82,19 +25,6 @@ export declare class UtilFunc {
82
25
  * @returns hash
83
26
  */
84
27
  static calcHash(str: string, method?: HashMethod): string;
85
- /**等待 timeMs 毫秒
86
- * @async
87
- * @param timeMs - 等待的毫秒数
88
- * @returns
89
- */
90
- static sleep<T>(timeMs: number): Promise<void>;
91
- /**等待 timeMs 毫秒
92
- * @async
93
- * @param timeMs - 等待的毫秒数
94
- * @param result - 结果
95
- * @returns
96
- */
97
- static sleep<T>(timeMs: number, result: T): Promise<T>;
98
28
  /**是否需要检查环境 */
99
29
  private static checkEnv;
100
30
  /**是否有正在运行的exec */
@@ -111,98 +41,6 @@ export declare class UtilFunc {
111
41
  stdout: string;
112
42
  stderr: string;
113
43
  }>;
114
- /**获得一个永不完成的Promise单例 */
115
- static getNeverResolvedPromise<T>(): Promise<T>;
116
- /**重复尝试promise
117
- * @async
118
- * @param proc - 发起函数
119
- * @param verify - 验证函数
120
- * @param retries - 重试参数 默认 延迟:0ms 间隔:180_000ms 重试:3次
121
- * @returns 重复结果
122
- */
123
- static retryPromise<T>(proc: () => Promise<T>, verify?: StatusVerifyFn<T>, retries?: PromiseRetries): Promise<PromiseRetryResult<T>>;
124
- /**创建一个限时的Promise
125
- * @param func - 处理函数
126
- * @param timeLimit - 毫秒限时
127
- * @returns 超时则返回 处理函数委托 完成则返回结果
128
- */
129
- static timelimitPromise<T>(func: () => MPromise<T>, timeLimit?: number): Promise<SuccessOut<T> | TimeoutOut<T>>;
130
- /**对对象的每个属性应用映射函数,并返回一个新的对象。
131
- * @template T - 对象的类型
132
- * @param obj - 要处理的对象
133
- * @param mapper - 映射函数,接受一个值和一个键,返回一个新的值
134
- * @returns - 一个新的对象,它的属性是原对象的属性经过映射函数处理后的结果
135
- */
136
- static mapEntries<T extends AnyRecord>(obj: T, mapper: (key: keyof T, value: T[keyof T]) => T[keyof T]): T;
137
- /**遍历对象的所有字段
138
- * @param obj - 对象
139
- * @param callback - 回调函数
140
- */
141
- static eachField(obj: JToken, callback: EachFieldCallback): void;
142
- /**将JToken转换为字符串
143
- * @param token - 待转换的Token
144
- * @param opt - 可选参数
145
- * @param opt.space - 插入的空格 数字为空格数量 默认为制表符\t
146
- * @param opt.compress - 使用紧凑风格 将会用/\uF121\uF122\uF123.+\uF121\uF122\uF123/作为特殊标记, 原始文本内若出现相同格式将会产生错误
147
- * @param opt.compressThreshold - 紧凑风格 压缩阈值 默认100
148
- * @returns 转换完成的字符串
149
- */
150
- static stringifyJToken(token: JToken | IJData, opt?: StringifyOpt): string;
151
- /**验证一个变量的类型是否为 T
152
- * @template T - 验证类型
153
- * @param t - 验证目标
154
- */
155
- static assertType<T>(t: T): T;
156
- /**验证一个变量的类型是否为字面量
157
- * 仅限浅层
158
- * @template T - 验证类型
159
- * @param t - 验证目标
160
- */
161
- static assertLiteral<T>(t: Literal<T>): T;
162
- /**深克隆 序列化并反序列化
163
- * @template T - JToken类型的泛型
164
- * @param obj - 克隆目标
165
- * @returns 克隆结果
166
- */
167
- static deepClone<T extends JToken>(obj: T): T;
168
- /**是否为安全的数字
169
- * 非NaN 非null/undefined
170
- * 且是数字
171
- * @param num - 所要检测的数字
172
- * @returns 是否安全
173
- */
174
- static isSafeNumber(num: unknown): boolean;
175
- /**移除多行字符串中每行开始的最小空格数。
176
- *
177
- * @param input - 需要处理的多行 字符串模板 或 字符串。
178
- * @param values - 插入模板字符串中的值。
179
- * @returns 返回处理后的字符串,每行开始的空格数已被最小化。
180
- *
181
- * @example
182
- * const name = 'World';
183
- * const str = dedent`
184
- * Hello,
185
- * ${name}!
186
- * `;
187
- * console.log(str);
188
- * // 输出:
189
- * // Hello,
190
- * // World!
191
- */
192
- static dedent(input: TemplateStringsArray | string, ...values: any[]): string;
193
- /**抛出错误
194
- * @param message - 错误信息
195
- * @param lvl - 日志等级
196
- * @param opt - 额外参数
197
- */
198
- static throwError(message: string, lvl?: LogLevel, opt?: {}): never;
199
- /**获取函数调用位置 getFunctionLocation
200
- * @param stack - 深度 默认1, 即getFuncLoc函数被调用的位置
201
- */
202
- static getFuncLoc(stack?: number): {
203
- filePath: string;
204
- lineNumber: `${number}:${number}`;
205
- } | undefined;
206
44
  private static publicIp?;
207
45
  /**获取当前公网ipv4 */
208
46
  static getPublicIpv4(): Promise<string>;
@@ -223,104 +61,8 @@ export declare class UtilFunc {
223
61
  * @since Node.js 13.2,Node.js开始支持动态import。
224
62
  */
225
63
  static dynamicImport(moduleName: string): Promise<any>;
226
- /**缓存池 */
227
- static cachePool: WeakMap<Function, Map<string, {
228
- result: any;
229
- timestamp: number;
230
- }>>;
231
- /**创建一个带有缓存有效期的memoize函数
232
- * 只在传入值均为JToken时有效
233
- * @param fn - 需要被memoize的函数
234
- * @param expiry - 缓存的有效期 毫秒 默认为Infinity, 表示缓存永不过期。
235
- * @returns 返回一个新的函数,这个函数在调用时会尝试从缓存中获取结果,如果缓存不存在或已过期,就会调用原函数并缓存其结果。
236
- */
237
- 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;
238
- /**代办表 用于队列处理等待 */
239
- static pendingMap: Record<Keyable, AnyFunc[]>;
240
- /**队列处理
241
- * 等待标签为 flag 的队列
242
- * 直到排在之前的任务全部完成再处理当前Promise
243
- * @param flag - 队列标签
244
- * @param task - 任务逻辑
245
- * @returns 处理结果
246
- */
247
- static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T>;
248
- /**队列获取目标的代办事件数
249
- * @param flag - 队列标签
250
- */
251
- static queueLength(flag: Keyable): number;
252
- /**创建一个Outcome */
253
- static outcome<K extends Keyable, V>(key: K, value: V): Outcome<K, V>;
254
- /**处理联合值
255
- * @param t - 目标值
256
- * @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
257
- * @returns 任意处理函数的返回值
258
- */
259
- static matchProc<T extends Matchable<Keyable>, P extends UnionToIntersection<{
260
- [K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
261
- }>>(t: T, procObj: P): P extends Record<any, AnyFunc> ? {
262
- [K in keyof P]: ReturnType<P[K]>;
263
- }[keyof P] : never;
264
- /**处理部分联合值
265
- * @param t - 目标值
266
- * @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
267
- * @returns 任意处理函数的返回值
268
- */
269
- static matchPartialProc<T extends Matchable<Keyable>, P extends Partial<{
270
- [K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
271
- }>>(t: T, procObj: P): (P extends PRecord<Keyable, AnyFunc> ? {
272
- [K in keyof P]: P[K] extends AnyFunc ? ReturnType<P[K]> : undefined;
273
- }[keyof P] : never) | undefined;
274
- /**根据典型的成功或失败状态运行函数
275
- * @param t - 目标值
276
- * @param sucessFunc - 成功则运行的函数 (result)=>any
277
- * @param failedFunc - 失败则运行的函数 (result)=>any
278
- * @param noneFunc - 无结果或不匹配时运行的函数 ()=>any
279
- * @returns 非成功或失败时返回 None
280
- */
281
- static sucesProc<T extends Matchable<StatusSymbol>, S extends (arg: ExtractOutcome<T, SuccessLike>['result']) => unknown, F extends (arg: ExtractOutcome<T, FailedLike>['result']) => unknown = (arg: ExtractOutcome<T, FailedLike>['result']) => None, N extends () => unknown = () => None>(t: T, sucessFunc: S, failedFunc?: F, noneFunc?: N): ReturnType<S> | ReturnType<F> | ReturnType<N>;
282
- /**是失败的 */
283
- static isFailed<T>(tg: T): 'E' extends ProperSubsetCheck<symbol, T> ? boolean : T extends Matchable<FailedLike> ? true : MatchableFlag<T> extends Exclude<MatchableFlag<T>, FailedLike> ? false : boolean;
284
- /**是成功的 */
285
- static isSuccess<T>(tg: T): 'E' extends ProperSubsetCheck<symbol, T> ? boolean : T extends Matchable<SuccessLike> ? true : MatchableFlag<T> extends Exclude<MatchableFlag<T>, SuccessLike> ? false : boolean;
286
- /**类似空值 undefined null None
287
- * @param t - 检测目标
288
- * @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
289
- */
290
- static likeNone(t: unknown, strictLog?: boolean): t is None;
291
- /**验证一个值是否为空
292
- * 为空则抛异
293
- * @param t - 验证目标
294
- * @param errLog - 异常信息
295
- * @returns 排除None的原值
296
- */
297
- static expect<T>(t: T, errLog?: string): Exclude<T, None>;
298
- /**将传入函数包装为显式处理错误的函数
299
- * @param func - 待转换函数
300
- * @returns 转换完成的函数
301
- */
302
- static eitherize<T extends AnyFunc>(func: ReturnType<T> extends Promise<any> ? Error & "对异步函数请使用taskEitherize" : T): (...args: Parameters<T>) => Outcome<typeof Success, ReturnType<T>> | Outcome<typeof Failed, Error>;
303
- /**将传入的异步函数包装为显式处理错误的函数
304
- * @param func - 待转换函数
305
- * @returns 转换完成的函数
306
- */
307
- static taskEitherize<T extends (...args: any) => Promise<any>>(func: T): (...args: Parameters<T>) => Promise<Outcome<typeof Failed, Error> | Outcome<typeof Success, Awaited<ReturnType<T>>>>;
308
- /**将hh:mm:ss,ms格式转换为毫秒 */
309
- static parseSrtTime(time: string): number;
310
- /**将毫秒转换为hh:mm:ss,ms格式 */
311
- static formatSrtTime(milliseconds: number): string;
312
- /**解析srt文本为SrtSegment[] */
313
- static parseSrt(srtText: string): SrtSegment[];
314
- /**转换json为srt文本 */
315
- static createSrt(segments: SrtSegment[]): string;
316
- /**立即执行传入的函数
317
- * @param fn - 需要立即执行的函数。
318
- * @returns 返回 fn 函数的执行结果。
319
- */
320
- static ivk<T extends () => any>(fn: T): ReturnType<T>;
321
- /**一个可供sort使用的从小到大排序的函数 */
322
- static s2l(a: number, b: number): number;
323
- /**一个可供sort使用的从大到小排序的函数 */
324
- static l2s(a: number, b: number): number;
325
64
  }
326
- export {};
65
+ declare const mixkey: "__utilFunc";
66
+ declare const fields: Exclude<(keyof typeof _UtilFunc)[], "prototype" | "length" | "name">;
67
+ export type UtilFunc = ComposedClass<typeof JsFunc, typeof _UtilFunc, typeof mixkey, typeof fields[number]>;
68
+ export declare const UtilFunc: UtilFunc;