@zwa73/utils 1.0.193 → 1.0.195
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/{QuickFunction.d.ts → QuickExport.d.ts} +1 -1
- package/dist/{QuickFunction.js → QuickExport.js} +2 -2
- package/dist/UtilClass.d.ts +7 -4
- package/dist/UtilClass.js +6 -3
- package/dist/UtilFP.js +3 -3
- package/dist/UtilFfmpegTools.js +3 -3
- package/dist/UtilFunctions.d.ts +81 -72
- package/dist/UtilFunctions.js +170 -145
- package/dist/UtilInterfaces.d.ts +3 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/package.json +1 -1
- package/src/{QuickFunction.ts → QuickExport.ts} +1 -0
- package/src/UtilClass.ts +10 -7
- package/src/UtilFP.ts +1 -1
- package/src/UtilFfmpegTools.ts +1 -1
- package/src/UtilFunctions.ts +194 -172
- package/src/UtilInterfaces.ts +3 -1
- package/src/index.ts +2 -3
- package/dist/LiteFunction.d.ts +0 -9
- package/dist/LiteFunction.js +0 -20
- package/src/LiteFunction.ts +0 -18
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { UtilFT } from "./UtilFileTools";
|
|
2
2
|
import { UtilFunc } from "./UtilFunctions";
|
|
3
|
-
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, dedent: typeof UtilFunc.dedent, throwError: typeof UtilFunc.throwError, eitherize: typeof UtilFunc.eitherize, taskEitherize: typeof UtilFunc.taskEitherize, memoize: typeof UtilFunc.memoize;
|
|
3
|
+
export declare const outcome: typeof UtilFunc.outcome, matchProc: typeof UtilFunc.matchProc, sucesProc: typeof UtilFunc.sucesProc, isFailed: typeof UtilFunc.isFailed, isSafeNumber: typeof UtilFunc.isSafeNumber, isSuccess: typeof UtilFunc.isSuccess, likeNone: typeof UtilFunc.likeNone, expect: typeof UtilFunc.expect, assertType: typeof UtilFunc.assertType, assertLiteral: typeof UtilFunc.assertLiteral, deepClone: typeof UtilFunc.deepClone, sleep: typeof UtilFunc.sleep, stringifyJToken: typeof UtilFunc.stringifyJToken, getTime: typeof UtilFunc.getTime, mapEntries: typeof UtilFunc.mapEntries, dedent: typeof UtilFunc.dedent, throwError: typeof UtilFunc.throwError, eitherize: typeof UtilFunc.eitherize, taskEitherize: typeof UtilFunc.taskEitherize, memoize: typeof UtilFunc.memoize, ivk: typeof UtilFunc.ivk, l2s: typeof UtilFunc.l2s, s2l: typeof UtilFunc.s2l;
|
|
4
4
|
export declare const stylizePath: typeof UtilFT.stylizePath, posixizePath: typeof UtilFT.posixizePath, win32izePath: typeof UtilFT.win32izePath, currosizePath: typeof UtilFT.currosizePath;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.currosizePath = exports.win32izePath = exports.posixizePath = exports.stylizePath = exports.memoize = exports.taskEitherize = exports.eitherize = exports.throwError = exports.dedent = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
|
|
3
|
+
exports.currosizePath = exports.win32izePath = exports.posixizePath = exports.stylizePath = exports.s2l = exports.l2s = exports.ivk = exports.memoize = exports.taskEitherize = exports.eitherize = exports.throwError = exports.dedent = exports.mapEntries = exports.getTime = exports.stringifyJToken = exports.sleep = exports.deepClone = exports.assertLiteral = exports.assertType = exports.expect = exports.likeNone = exports.isSuccess = exports.isSafeNumber = exports.isFailed = exports.sucesProc = exports.matchProc = exports.outcome = void 0;
|
|
4
4
|
const UtilFileTools_1 = require("./UtilFileTools");
|
|
5
5
|
const UtilFunctions_1 = require("./UtilFunctions");
|
|
6
6
|
const UtilSymbol_1 = require("./UtilSymbol");
|
|
7
|
-
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError, exports.eitherize = UtilFunctions_1.UtilFunc.eitherize, exports.taskEitherize = UtilFunctions_1.UtilFunc.taskEitherize, exports.memoize = UtilFunctions_1.UtilFunc.memoize;
|
|
7
|
+
exports.outcome = UtilFunctions_1.UtilFunc.outcome, exports.matchProc = UtilFunctions_1.UtilFunc.matchProc, exports.sucesProc = UtilFunctions_1.UtilFunc.sucesProc, exports.isFailed = UtilFunctions_1.UtilFunc.isFailed, exports.isSafeNumber = UtilFunctions_1.UtilFunc.isSafeNumber, exports.isSuccess = UtilFunctions_1.UtilFunc.isSuccess, exports.likeNone = UtilFunctions_1.UtilFunc.likeNone, exports.expect = UtilFunctions_1.UtilFunc.expect, exports.assertType = UtilFunctions_1.UtilFunc.assertType, exports.assertLiteral = UtilFunctions_1.UtilFunc.assertLiteral, exports.deepClone = UtilFunctions_1.UtilFunc.deepClone, exports.sleep = UtilFunctions_1.UtilFunc.sleep, exports.stringifyJToken = UtilFunctions_1.UtilFunc.stringifyJToken, exports.getTime = UtilFunctions_1.UtilFunc.getTime, exports.mapEntries = UtilFunctions_1.UtilFunc.mapEntries, exports.dedent = UtilFunctions_1.UtilFunc.dedent, exports.throwError = UtilFunctions_1.UtilFunc.throwError, exports.eitherize = UtilFunctions_1.UtilFunc.eitherize, exports.taskEitherize = UtilFunctions_1.UtilFunc.taskEitherize, exports.memoize = UtilFunctions_1.UtilFunc.memoize, exports.ivk = UtilFunctions_1.UtilFunc.ivk, exports.l2s = UtilFunctions_1.UtilFunc.l2s, exports.s2l = UtilFunctions_1.UtilFunc.s2l;
|
|
8
8
|
exports.stylizePath = UtilFileTools_1.UtilFT.stylizePath, exports.posixizePath = UtilFileTools_1.UtilFT.posixizePath, exports.win32izePath = UtilFileTools_1.UtilFT.win32izePath, exports.currosizePath = UtilFileTools_1.UtilFT.currosizePath;
|
|
9
9
|
if (false) {
|
|
10
10
|
let aaser = (0, exports.assertLiteral)({ a: 1 });
|
package/dist/UtilClass.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Keyable, Literal } from "./UtilInterfaces";
|
|
1
|
+
import { Keyable, Literal, MPromise } from "./UtilInterfaces";
|
|
2
2
|
import Handlebars from 'handlebars';
|
|
3
3
|
/**函数管道器 */
|
|
4
4
|
export declare class Piper<Arg, Result = Arg> {
|
|
@@ -18,7 +18,7 @@ export declare class Piper<Arg, Result = Arg> {
|
|
|
18
18
|
/**直接调用 */
|
|
19
19
|
invoke(arg: Arg): Result;
|
|
20
20
|
}
|
|
21
|
-
type StreamOperation<T, U> = (item: T) =>
|
|
21
|
+
type StreamOperation<T, U> = (item: T) => MPromise<U>;
|
|
22
22
|
/**并行流 */
|
|
23
23
|
export declare class Stream<T> implements Iterable<T> {
|
|
24
24
|
/**并发数*/
|
|
@@ -27,8 +27,11 @@ export declare class Stream<T> implements Iterable<T> {
|
|
|
27
27
|
/**加工函数列表*/
|
|
28
28
|
private _operation;
|
|
29
29
|
private constructor();
|
|
30
|
-
/**从arraylike创建流
|
|
31
|
-
|
|
30
|
+
/**从arraylike创建流
|
|
31
|
+
* @param args - arraylike
|
|
32
|
+
* @param concurrent - 并发数 默认 1
|
|
33
|
+
*/
|
|
34
|
+
static from<T>(args: ArrayLike<T>, concurrent?: number): Stream<T>;
|
|
32
35
|
/**从数组创建流 */
|
|
33
36
|
static of<T>(...args: T[]): Stream<T>;
|
|
34
37
|
/**设置并发数 */
|
package/dist/UtilClass.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Hbs = exports.Stream = exports.Piper = void 0;
|
|
7
|
-
const
|
|
7
|
+
const QuickExport_1 = require("./QuickExport");
|
|
8
8
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
9
9
|
const UtilLogger_1 = require("./UtilLogger");
|
|
10
10
|
/**函数管道器 */
|
|
@@ -49,7 +49,10 @@ class Stream {
|
|
|
49
49
|
this._list = new Array(...base);
|
|
50
50
|
this._concurrent = concurrent;
|
|
51
51
|
}
|
|
52
|
-
/**从arraylike创建流
|
|
52
|
+
/**从arraylike创建流
|
|
53
|
+
* @param args - arraylike
|
|
54
|
+
* @param concurrent - 并发数 默认 1
|
|
55
|
+
*/
|
|
53
56
|
static from(args, concurrent = 1) {
|
|
54
57
|
return new Stream(Array.from(args), concurrent);
|
|
55
58
|
}
|
|
@@ -74,7 +77,7 @@ class Stream {
|
|
|
74
77
|
return [[...this]];
|
|
75
78
|
const size = this.length;
|
|
76
79
|
const result = [];
|
|
77
|
-
(0,
|
|
80
|
+
(0, QuickExport_1.matchProc)(mode, {
|
|
78
81
|
//轮询平均分
|
|
79
82
|
'average': () => {
|
|
80
83
|
for (let i = 0; i < count; i++) {
|
package/dist/UtilFP.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UtilFP = void 0;
|
|
4
|
-
const
|
|
4
|
+
const QuickExport_1 = require("./QuickExport");
|
|
5
5
|
/**常用函数式编程库 */
|
|
6
6
|
var UtilFP;
|
|
7
7
|
(function (UtilFP) {
|
|
@@ -55,9 +55,9 @@ var UtilFP;
|
|
|
55
55
|
}
|
|
56
56
|
UtilFP.map = map;
|
|
57
57
|
/**创建在传入值为失败时不运行的函数 */
|
|
58
|
-
UtilFP.chain = (f) => (arg) => (0,
|
|
58
|
+
UtilFP.chain = (f) => (arg) => (0, QuickExport_1.isFailed)(arg) ? arg : f(arg);
|
|
59
59
|
/**创建在传入值为失败时才会尝试运行的函数 */
|
|
60
|
-
UtilFP.alt = (f) => (arg) => (0,
|
|
60
|
+
UtilFP.alt = (f) => (arg) => (0, QuickExport_1.isFailed)(arg) ? f(arg) : arg;
|
|
61
61
|
/**
|
|
62
62
|
let asd = bindTo("sss",123,{abc:223});//?
|
|
63
63
|
let sumvoid = ()=>10;
|
package/dist/UtilFfmpegTools.js
CHANGED
|
@@ -32,7 +32,7 @@ const pathe_1 = __importDefault(require("pathe"));
|
|
|
32
32
|
const fs = __importStar(require("fs"));
|
|
33
33
|
const UtilLogger_1 = require("./UtilLogger");
|
|
34
34
|
const UtilClass_1 = require("./UtilClass");
|
|
35
|
-
const
|
|
35
|
+
const QuickExport_1 = require("./QuickExport");
|
|
36
36
|
/**ffmpeg工具类
|
|
37
37
|
*/
|
|
38
38
|
class SFfmpegTool {
|
|
@@ -193,11 +193,11 @@ class SFfmpegTool {
|
|
|
193
193
|
static async isMono(filePath) {
|
|
194
194
|
const metadata = await SFfmpegTool.getAudioMetaData(filePath);
|
|
195
195
|
if (metadata == null)
|
|
196
|
-
(0,
|
|
196
|
+
(0, QuickExport_1.throwError)("SFfmpegTool.isMono 获取音频元数据失败");
|
|
197
197
|
// 检查音频流的声道数
|
|
198
198
|
const audioStream = metadata.streams.find(stream => stream.codec_type === 'audio');
|
|
199
199
|
if (audioStream == null)
|
|
200
|
-
(0,
|
|
200
|
+
(0, QuickExport_1.throwError)("SFfmpegTool.isMono 未找到音频流");
|
|
201
201
|
return audioStream.channels === 1;
|
|
202
202
|
}
|
|
203
203
|
//多线程处理
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PRecord, AnyFunc, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Outcome, ReqVerifyFn, ProperSubsetCheck, UnionToIntersection, AnyRecord, AllExtends, SrtSegment } from "./UtilInterfaces";
|
|
1
|
+
import { PRecord, AnyFunc, ExtractOutcome, IJData, JObject, JToken, Keyable, Literal, Matchable, MatchableFlag, Outcome, ReqVerifyFn, ProperSubsetCheck, UnionToIntersection, AnyRecord, AllExtends, SrtSegment, MPromise } 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"];
|
|
@@ -119,7 +119,7 @@ export declare class UtilFunc {
|
|
|
119
119
|
* @param timeLimit - 毫秒限时
|
|
120
120
|
* @returns 超时则返回 处理函数委托 完成则返回结果
|
|
121
121
|
*/
|
|
122
|
-
static timelimitPromise<T>(func: () =>
|
|
122
|
+
static timelimitPromise<T>(func: () => MPromise<T>, timeLimit?: number): Promise<SuccessOut<T> | TimeoutOut<T>>;
|
|
123
123
|
/**对对象的每个属性应用映射函数,并返回一个新的对象。
|
|
124
124
|
* @template T - 对象的类型
|
|
125
125
|
* @param obj - 要处理的对象
|
|
@@ -141,66 +141,6 @@ export declare class UtilFunc {
|
|
|
141
141
|
* @returns 转换完成的字符串
|
|
142
142
|
*/
|
|
143
143
|
static stringifyJToken(token: JToken | IJData, opt?: StringifyOpt): string;
|
|
144
|
-
/**代办表 用于队列处理等待 */
|
|
145
|
-
static pendingMap: Record<Keyable, AnyFunc[]>;
|
|
146
|
-
/**队列处理
|
|
147
|
-
* 等待标签为 flag 的队列
|
|
148
|
-
* 直到排在之前的任务全部完成再处理当前Promise
|
|
149
|
-
* @param flag - 队列标签
|
|
150
|
-
* @param task - 任务逻辑
|
|
151
|
-
* @returns 处理结果
|
|
152
|
-
*/
|
|
153
|
-
static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T>;
|
|
154
|
-
/**队列获取目标的代办事件数
|
|
155
|
-
* @param flag - 队列标签
|
|
156
|
-
*/
|
|
157
|
-
static queueLength(flag: Keyable): number;
|
|
158
|
-
/**创建一个Outcome */
|
|
159
|
-
static outcome<K extends Keyable, V>(key: K, value: V): Outcome<K, V>;
|
|
160
|
-
/**处理联合值
|
|
161
|
-
* @param t - 目标值
|
|
162
|
-
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
163
|
-
* @returns 任意处理函数的返回值
|
|
164
|
-
*/
|
|
165
|
-
static matchProc<T extends Matchable<Keyable>, P extends UnionToIntersection<{
|
|
166
|
-
[K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
|
|
167
|
-
}>>(t: T, procObj: P): P extends Record<any, AnyFunc> ? {
|
|
168
|
-
[K in keyof P]: ReturnType<P[K]>;
|
|
169
|
-
}[keyof P] : never;
|
|
170
|
-
/**处理部分联合值
|
|
171
|
-
* @param t - 目标值
|
|
172
|
-
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
173
|
-
* @returns 任意处理函数的返回值
|
|
174
|
-
*/
|
|
175
|
-
static matchPartialProc<T extends Matchable<Keyable>, P extends Partial<{
|
|
176
|
-
[K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
|
|
177
|
-
}>>(t: T, procObj: P): (P extends PRecord<Keyable, AnyFunc> ? {
|
|
178
|
-
[K in keyof P]: P[K] extends AnyFunc ? ReturnType<P[K]> : undefined;
|
|
179
|
-
}[keyof P] : never) | undefined;
|
|
180
|
-
/**根据典型的成功或失败状态运行函数
|
|
181
|
-
* @param t - 目标值
|
|
182
|
-
* @param sucessFunc - 成功则运行的函数 (result)=>any
|
|
183
|
-
* @param failedFunc - 失败则运行的函数 (result)=>any
|
|
184
|
-
* @param noneFunc - 无结果或不匹配时运行的函数 ()=>any
|
|
185
|
-
* @returns 非成功或失败时返回 None
|
|
186
|
-
*/
|
|
187
|
-
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>;
|
|
188
|
-
/**是失败的 */
|
|
189
|
-
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;
|
|
190
|
-
/**是成功的 */
|
|
191
|
-
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;
|
|
192
|
-
/**类似空值 undefined null None
|
|
193
|
-
* @param t - 检测目标
|
|
194
|
-
* @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
|
|
195
|
-
*/
|
|
196
|
-
static likeNone(t: unknown, strictLog?: boolean): t is None;
|
|
197
|
-
/**验证一个值是否为空
|
|
198
|
-
* 为空则抛异
|
|
199
|
-
* @param t - 验证目标
|
|
200
|
-
* @param errLog - 异常信息
|
|
201
|
-
* @returns 排除None的原值
|
|
202
|
-
*/
|
|
203
|
-
static expect<T>(t: T, errLog?: string): Exclude<T, None>;
|
|
204
144
|
/**验证一个变量的类型是否为 T
|
|
205
145
|
* @template T - 验证类型
|
|
206
146
|
* @param t - 验证目标
|
|
@@ -259,16 +199,6 @@ export declare class UtilFunc {
|
|
|
259
199
|
private static publicIp?;
|
|
260
200
|
/**获取当前公网ipv4 */
|
|
261
201
|
static getPublicIpv4(): Promise<string>;
|
|
262
|
-
/**将传入函数包装为显式处理错误的函数
|
|
263
|
-
* @param func - 待转换函数
|
|
264
|
-
* @returns 转换完成的函数
|
|
265
|
-
*/
|
|
266
|
-
static eitherize<T extends AnyFunc>(func: T): (...args: Parameters<T>) => Outcome<typeof Success, ReturnType<T>> | Outcome<typeof Failed, Error>;
|
|
267
|
-
/**将传入的异步函数包装为显式处理错误的函数
|
|
268
|
-
* @param func - 待转换函数
|
|
269
|
-
* @returns 转换完成的函数
|
|
270
|
-
*/
|
|
271
|
-
static taskEitherize<T extends (...args: any) => Promise<any>>(func: T): (...args: Parameters<T>) => Promise<Outcome<typeof Failed, Error> | Outcome<typeof Success, Awaited<ReturnType<T>>>>;
|
|
272
202
|
/**动态导入模块的函数。这个函数是为了在TypeScript的模块系统配置为CommonJS时,防止动态import被转译为require而设计的。
|
|
273
203
|
* 使用这个函数,你可以在TypeScript中动态地导入模块,而不需要担心import()被转译为require()。
|
|
274
204
|
* 请注意,这个函数使用了eval(),可能会带来安全风险。
|
|
@@ -298,6 +228,76 @@ export declare class UtilFunc {
|
|
|
298
228
|
* @returns 返回一个新的函数,这个函数在调用时会尝试从缓存中获取结果,如果缓存不存在或已过期,就会调用原函数并缓存其结果。
|
|
299
229
|
*/
|
|
300
230
|
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;
|
|
231
|
+
/**代办表 用于队列处理等待 */
|
|
232
|
+
static pendingMap: Record<Keyable, AnyFunc[]>;
|
|
233
|
+
/**队列处理
|
|
234
|
+
* 等待标签为 flag 的队列
|
|
235
|
+
* 直到排在之前的任务全部完成再处理当前Promise
|
|
236
|
+
* @param flag - 队列标签
|
|
237
|
+
* @param task - 任务逻辑
|
|
238
|
+
* @returns 处理结果
|
|
239
|
+
*/
|
|
240
|
+
static queueProc<T>(flag: Keyable, task: () => Promise<T>): Promise<T>;
|
|
241
|
+
/**队列获取目标的代办事件数
|
|
242
|
+
* @param flag - 队列标签
|
|
243
|
+
*/
|
|
244
|
+
static queueLength(flag: Keyable): number;
|
|
245
|
+
/**创建一个Outcome */
|
|
246
|
+
static outcome<K extends Keyable, V>(key: K, value: V): Outcome<K, V>;
|
|
247
|
+
/**处理联合值
|
|
248
|
+
* @param t - 目标值
|
|
249
|
+
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
250
|
+
* @returns 任意处理函数的返回值
|
|
251
|
+
*/
|
|
252
|
+
static matchProc<T extends Matchable<Keyable>, P extends UnionToIntersection<{
|
|
253
|
+
[K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
|
|
254
|
+
}>>(t: T, procObj: P): P extends Record<any, AnyFunc> ? {
|
|
255
|
+
[K in keyof P]: ReturnType<P[K]>;
|
|
256
|
+
}[keyof P] : never;
|
|
257
|
+
/**处理部分联合值
|
|
258
|
+
* @param t - 目标值
|
|
259
|
+
* @param procObj - 所有可能的id组成的处理函数映射 (status, result)=>any
|
|
260
|
+
* @returns 任意处理函数的返回值
|
|
261
|
+
*/
|
|
262
|
+
static matchPartialProc<T extends Matchable<Keyable>, P extends Partial<{
|
|
263
|
+
[K in MatchableFlag<T>]: (k: K, v: ExtractOutcome<T, MatchableFlag<K>>['result']) => unknown;
|
|
264
|
+
}>>(t: T, procObj: P): (P extends PRecord<Keyable, AnyFunc> ? {
|
|
265
|
+
[K in keyof P]: P[K] extends AnyFunc ? ReturnType<P[K]> : undefined;
|
|
266
|
+
}[keyof P] : never) | undefined;
|
|
267
|
+
/**根据典型的成功或失败状态运行函数
|
|
268
|
+
* @param t - 目标值
|
|
269
|
+
* @param sucessFunc - 成功则运行的函数 (result)=>any
|
|
270
|
+
* @param failedFunc - 失败则运行的函数 (result)=>any
|
|
271
|
+
* @param noneFunc - 无结果或不匹配时运行的函数 ()=>any
|
|
272
|
+
* @returns 非成功或失败时返回 None
|
|
273
|
+
*/
|
|
274
|
+
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>;
|
|
275
|
+
/**是失败的 */
|
|
276
|
+
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;
|
|
277
|
+
/**是成功的 */
|
|
278
|
+
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;
|
|
279
|
+
/**类似空值 undefined null None
|
|
280
|
+
* @param t - 检测目标
|
|
281
|
+
* @param strictLog - 应该严格等于None 否则将输出警告 但任然返回true
|
|
282
|
+
*/
|
|
283
|
+
static likeNone(t: unknown, strictLog?: boolean): t is None;
|
|
284
|
+
/**验证一个值是否为空
|
|
285
|
+
* 为空则抛异
|
|
286
|
+
* @param t - 验证目标
|
|
287
|
+
* @param errLog - 异常信息
|
|
288
|
+
* @returns 排除None的原值
|
|
289
|
+
*/
|
|
290
|
+
static expect<T>(t: T, errLog?: string): Exclude<T, None>;
|
|
291
|
+
/**将传入函数包装为显式处理错误的函数
|
|
292
|
+
* @param func - 待转换函数
|
|
293
|
+
* @returns 转换完成的函数
|
|
294
|
+
*/
|
|
295
|
+
static eitherize<T extends AnyFunc>(func: T): (...args: Parameters<T>) => Outcome<typeof Success, ReturnType<T>> | Outcome<typeof Failed, Error>;
|
|
296
|
+
/**将传入的异步函数包装为显式处理错误的函数
|
|
297
|
+
* @param func - 待转换函数
|
|
298
|
+
* @returns 转换完成的函数
|
|
299
|
+
*/
|
|
300
|
+
static taskEitherize<T extends (...args: any) => Promise<any>>(func: T): (...args: Parameters<T>) => Promise<Outcome<typeof Failed, Error> | Outcome<typeof Success, Awaited<ReturnType<T>>>>;
|
|
301
301
|
/**将hh:mm:ss,ms格式转换为毫秒 */
|
|
302
302
|
static parseSrtTime(time: string): number;
|
|
303
303
|
/**将毫秒转换为hh:mm:ss,ms格式 */
|
|
@@ -306,5 +306,14 @@ export declare class UtilFunc {
|
|
|
306
306
|
static parseSrt(srtText: string): SrtSegment[];
|
|
307
307
|
/**转换json为srt文本 */
|
|
308
308
|
static createSrt(segments: SrtSegment[]): string;
|
|
309
|
+
/**立即执行传入的函数
|
|
310
|
+
* @param fn - 需要立即执行的函数。
|
|
311
|
+
* @returns 返回 fn 函数的执行结果。
|
|
312
|
+
*/
|
|
313
|
+
static ivk<T extends () => any>(fn: T): ReturnType<T>;
|
|
314
|
+
/**一个可供sort使用的从小到大排序的函数 */
|
|
315
|
+
static s2l(a: number, b: number): number;
|
|
316
|
+
/**一个可供sort使用的从大到小排序的函数 */
|
|
317
|
+
static l2s(a: number, b: number): number;
|
|
309
318
|
}
|
|
310
319
|
export {};
|