@whitesev/utils 2.9.12 → 2.10.0
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/README.md +176 -176
- package/dist/index.amd.js +206 -117
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +206 -117
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +206 -117
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +206 -117
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +206 -117
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +206 -117
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Dictionary.d.ts +2 -0
- package/dist/types/src/Utils.d.ts +9 -2
- package/dist/types/src/types/Httpx.d.ts +1344 -1344
- package/dist/types/src/types/Log.d.ts +19 -19
- package/dist/types/src/types/Progress.d.ts +20 -20
- package/dist/types/src/types/React.d.ts +119 -119
- package/dist/types/src/types/TryCatch.d.ts +9 -9
- package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
- package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
- package/dist/types/src/types/Vue2.d.ts +166 -166
- package/dist/types/src/types/WindowApi.d.ts +14 -14
- package/dist/types/src/types/ajaxHooker.d.ts +155 -155
- package/dist/types/src/types/env.d.ts +7 -7
- package/dist/types/src/types/global.d.ts +31 -31
- package/package.json +26 -24
- package/src/ColorConversion.ts +118 -118
- package/src/CommonUtil.ts +301 -301
- package/src/DOMUtils.ts +251 -251
- package/src/Dictionary.ts +205 -199
- package/src/GBKEncoder.ts +108 -108
- package/src/Hooks.ts +73 -73
- package/src/Httpx.ts +1457 -1457
- package/src/LockFunction.ts +65 -62
- package/src/Log.ts +233 -233
- package/src/ModuleRaid.js +378 -360
- package/src/Progress.ts +108 -108
- package/src/TryCatch.ts +86 -86
- package/src/Utils.ts +3907 -3852
- package/src/UtilsCommon.ts +14 -14
- package/src/UtilsGMCookie.ts +273 -273
- package/src/UtilsGMMenu.ts +460 -460
- package/src/Vue.ts +233 -233
- package/src/WindowApi.ts +59 -59
- package/src/ajaxHooker/ajaxHooker.js +606 -538
- package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
- package/src/indexedDB.ts +497 -497
- package/src/types/Httpx.d.ts +1344 -1344
- package/src/types/Log.d.ts +19 -19
- package/src/types/Progress.d.ts +20 -20
- package/src/types/React.d.ts +119 -119
- package/src/types/TryCatch.d.ts +9 -9
- package/src/types/UtilsGMCookie.d.ts +93 -93
- package/src/types/UtilsGMMenu.d.ts +77 -77
- package/src/types/Vue2.d.ts +166 -166
- package/src/types/WindowApi.d.ts +14 -14
- package/src/types/ajaxHooker.d.ts +155 -155
- package/src/types/env.d.ts +7 -7
- package/src/types/global.d.ts +31 -31
package/src/Progress.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { CommonUtil } from "./CommonUtil";
|
|
2
|
-
import type { ProgressParamConfig } from "./types/Progress";
|
|
3
|
-
|
|
4
|
-
export class Progress {
|
|
5
|
-
#config: ProgressParamConfig = {
|
|
6
|
-
/**
|
|
7
|
-
* canvas元素节点
|
|
8
|
-
*/
|
|
9
|
-
canvasNode: null as any,
|
|
10
|
-
/**
|
|
11
|
-
* 绘制角度
|
|
12
|
-
*/
|
|
13
|
-
deg: 95,
|
|
14
|
-
/**
|
|
15
|
-
* 进度
|
|
16
|
-
*/
|
|
17
|
-
progress: 0,
|
|
18
|
-
/**
|
|
19
|
-
* 绘制的线宽度
|
|
20
|
-
*/
|
|
21
|
-
lineWidth: 10,
|
|
22
|
-
/**
|
|
23
|
-
* 绘制的背景颜色
|
|
24
|
-
*/
|
|
25
|
-
lineBgColor: "#1e637c",
|
|
26
|
-
/**
|
|
27
|
-
* 绘制的线的颜色
|
|
28
|
-
*/
|
|
29
|
-
lineColor: "#25deff",
|
|
30
|
-
/**
|
|
31
|
-
* 绘制的字体颜色
|
|
32
|
-
*/
|
|
33
|
-
textColor: "#000000",
|
|
34
|
-
/**
|
|
35
|
-
* 绘制的字体大小(px)
|
|
36
|
-
*/
|
|
37
|
-
fontSize: 22,
|
|
38
|
-
/**
|
|
39
|
-
* 绘制的圆的半径
|
|
40
|
-
*/
|
|
41
|
-
circleRadius: 50,
|
|
42
|
-
};
|
|
43
|
-
#ctx: CanvasRenderingContext2D;
|
|
44
|
-
#width: number;
|
|
45
|
-
#height: number;
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @param paramConfig 配置信息
|
|
49
|
-
*/
|
|
50
|
-
constructor(paramConfig: ProgressParamConfig) {
|
|
51
|
-
this.#config = CommonUtil.assign(this.#config, paramConfig);
|
|
52
|
-
if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
|
|
53
|
-
throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
|
|
54
|
-
}
|
|
55
|
-
/* 获取画笔 */
|
|
56
|
-
const ctx = this.#config.canvasNode.getContext("2d");
|
|
57
|
-
if (ctx == null) {
|
|
58
|
-
throw new Error("Utils.Progress 获取画笔失败");
|
|
59
|
-
}
|
|
60
|
-
this.#ctx = ctx;
|
|
61
|
-
/* 元素宽度 */
|
|
62
|
-
this.#width = this.#config.canvasNode.width;
|
|
63
|
-
/* 元素高度 */
|
|
64
|
-
this.#height = this.#config.canvasNode.height;
|
|
65
|
-
/* 清除锯齿 */
|
|
66
|
-
if (window.devicePixelRatio) {
|
|
67
|
-
this.#config.canvasNode.style.width = `${this.#width}px`;
|
|
68
|
-
this.#config.canvasNode.style.height = `${this.#height}px`;
|
|
69
|
-
this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
|
|
70
|
-
this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
|
|
71
|
-
this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
|
72
|
-
}
|
|
73
|
-
/* 设置线宽 */
|
|
74
|
-
this.#ctx.lineWidth = this.#config.lineWidth;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* 绘制
|
|
78
|
-
*/
|
|
79
|
-
draw() {
|
|
80
|
-
const degActive = (this.#config.progress * 360) / 100;
|
|
81
|
-
/* 清除画布 */
|
|
82
|
-
this.#ctx.clearRect(0, 0, this.#width, this.#height);
|
|
83
|
-
/* 开始绘制底圆 */
|
|
84
|
-
this.#ctx.beginPath();
|
|
85
|
-
this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
|
|
86
|
-
this.#ctx.strokeStyle = this.#config.lineBgColor;
|
|
87
|
-
this.#ctx.stroke();
|
|
88
|
-
/* 开始绘制动态圆 */
|
|
89
|
-
this.#ctx.beginPath();
|
|
90
|
-
this.#ctx.arc(
|
|
91
|
-
this.#width / 2,
|
|
92
|
-
this.#height / 2,
|
|
93
|
-
this.#config.circleRadius,
|
|
94
|
-
-Math.PI / 2,
|
|
95
|
-
(degActive * Math.PI) / 180 - Math.PI / 2
|
|
96
|
-
);
|
|
97
|
-
this.#ctx.strokeStyle = this.#config.lineColor;
|
|
98
|
-
this.#ctx.stroke();
|
|
99
|
-
/* 获取百分比 */
|
|
100
|
-
const txt = `${parseInt(this.#config.progress.toString())}%`;
|
|
101
|
-
this.#ctx.font = `${this.#config.fontSize}px SimHei`;
|
|
102
|
-
/* 获取文本宽度 */
|
|
103
|
-
const w = this.#ctx.measureText(txt).width;
|
|
104
|
-
const h = this.#config.fontSize / 2;
|
|
105
|
-
this.#ctx.fillStyle = this.#config.textColor;
|
|
106
|
-
this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
1
|
+
import { CommonUtil } from "./CommonUtil";
|
|
2
|
+
import type { ProgressParamConfig } from "./types/Progress";
|
|
3
|
+
|
|
4
|
+
export class Progress {
|
|
5
|
+
#config: ProgressParamConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* canvas元素节点
|
|
8
|
+
*/
|
|
9
|
+
canvasNode: null as any,
|
|
10
|
+
/**
|
|
11
|
+
* 绘制角度
|
|
12
|
+
*/
|
|
13
|
+
deg: 95,
|
|
14
|
+
/**
|
|
15
|
+
* 进度
|
|
16
|
+
*/
|
|
17
|
+
progress: 0,
|
|
18
|
+
/**
|
|
19
|
+
* 绘制的线宽度
|
|
20
|
+
*/
|
|
21
|
+
lineWidth: 10,
|
|
22
|
+
/**
|
|
23
|
+
* 绘制的背景颜色
|
|
24
|
+
*/
|
|
25
|
+
lineBgColor: "#1e637c",
|
|
26
|
+
/**
|
|
27
|
+
* 绘制的线的颜色
|
|
28
|
+
*/
|
|
29
|
+
lineColor: "#25deff",
|
|
30
|
+
/**
|
|
31
|
+
* 绘制的字体颜色
|
|
32
|
+
*/
|
|
33
|
+
textColor: "#000000",
|
|
34
|
+
/**
|
|
35
|
+
* 绘制的字体大小(px)
|
|
36
|
+
*/
|
|
37
|
+
fontSize: 22,
|
|
38
|
+
/**
|
|
39
|
+
* 绘制的圆的半径
|
|
40
|
+
*/
|
|
41
|
+
circleRadius: 50,
|
|
42
|
+
};
|
|
43
|
+
#ctx: CanvasRenderingContext2D;
|
|
44
|
+
#width: number;
|
|
45
|
+
#height: number;
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @param paramConfig 配置信息
|
|
49
|
+
*/
|
|
50
|
+
constructor(paramConfig: ProgressParamConfig) {
|
|
51
|
+
this.#config = CommonUtil.assign(this.#config, paramConfig);
|
|
52
|
+
if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
|
|
53
|
+
throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
|
|
54
|
+
}
|
|
55
|
+
/* 获取画笔 */
|
|
56
|
+
const ctx = this.#config.canvasNode.getContext("2d");
|
|
57
|
+
if (ctx == null) {
|
|
58
|
+
throw new Error("Utils.Progress 获取画笔失败");
|
|
59
|
+
}
|
|
60
|
+
this.#ctx = ctx;
|
|
61
|
+
/* 元素宽度 */
|
|
62
|
+
this.#width = this.#config.canvasNode.width;
|
|
63
|
+
/* 元素高度 */
|
|
64
|
+
this.#height = this.#config.canvasNode.height;
|
|
65
|
+
/* 清除锯齿 */
|
|
66
|
+
if (window.devicePixelRatio) {
|
|
67
|
+
this.#config.canvasNode.style.width = `${this.#width}px`;
|
|
68
|
+
this.#config.canvasNode.style.height = `${this.#height}px`;
|
|
69
|
+
this.#config.canvasNode.height = this.#height * window.devicePixelRatio;
|
|
70
|
+
this.#config.canvasNode.width = this.#width * window.devicePixelRatio;
|
|
71
|
+
this.#ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
|
72
|
+
}
|
|
73
|
+
/* 设置线宽 */
|
|
74
|
+
this.#ctx.lineWidth = this.#config.lineWidth;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 绘制
|
|
78
|
+
*/
|
|
79
|
+
draw() {
|
|
80
|
+
const degActive = (this.#config.progress * 360) / 100;
|
|
81
|
+
/* 清除画布 */
|
|
82
|
+
this.#ctx.clearRect(0, 0, this.#width, this.#height);
|
|
83
|
+
/* 开始绘制底圆 */
|
|
84
|
+
this.#ctx.beginPath();
|
|
85
|
+
this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
|
|
86
|
+
this.#ctx.strokeStyle = this.#config.lineBgColor;
|
|
87
|
+
this.#ctx.stroke();
|
|
88
|
+
/* 开始绘制动态圆 */
|
|
89
|
+
this.#ctx.beginPath();
|
|
90
|
+
this.#ctx.arc(
|
|
91
|
+
this.#width / 2,
|
|
92
|
+
this.#height / 2,
|
|
93
|
+
this.#config.circleRadius,
|
|
94
|
+
-Math.PI / 2,
|
|
95
|
+
(degActive * Math.PI) / 180 - Math.PI / 2
|
|
96
|
+
);
|
|
97
|
+
this.#ctx.strokeStyle = this.#config.lineColor;
|
|
98
|
+
this.#ctx.stroke();
|
|
99
|
+
/* 获取百分比 */
|
|
100
|
+
const txt = `${parseInt(this.#config.progress.toString())}%`;
|
|
101
|
+
this.#ctx.font = `${this.#config.fontSize}px SimHei`;
|
|
102
|
+
/* 获取文本宽度 */
|
|
103
|
+
const w = this.#ctx.measureText(txt).width;
|
|
104
|
+
const h = this.#config.fontSize / 2;
|
|
105
|
+
this.#ctx.fillStyle = this.#config.textColor;
|
|
106
|
+
this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
|
|
107
|
+
}
|
|
108
|
+
}
|
package/src/TryCatch.ts
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import type { UtilsTryCatchConfig, UtilsTryCatchType } from "./types/TryCatch";
|
|
2
|
-
|
|
3
|
-
export const TryCatch = function (...args: any) {
|
|
4
|
-
/* 定义变量和函数 */
|
|
5
|
-
let callbackFunction = null;
|
|
6
|
-
let context = null;
|
|
7
|
-
let handleError: (error: Error) => void = () => {};
|
|
8
|
-
let defaultDetails = {
|
|
9
|
-
log: true,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const TryCatchCore = {
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param paramDetails 配置
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
config(paramDetails: UtilsTryCatchConfig) {
|
|
19
|
-
defaultDetails = Object.assign(defaultDetails, paramDetails);
|
|
20
|
-
return TryCatchCore;
|
|
21
|
-
},
|
|
22
|
-
/**
|
|
23
|
-
* 处理错误
|
|
24
|
-
* @param handler
|
|
25
|
-
*/
|
|
26
|
-
error(handler: ((...args: any[]) => any) | string | ((...args: any[]) => any)) {
|
|
27
|
-
handleError = handler as (error: Error) => void;
|
|
28
|
-
return TryCatchCore;
|
|
29
|
-
},
|
|
30
|
-
/**
|
|
31
|
-
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
32
|
-
* @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
33
|
-
* @param __context__ 待执行函数的作用域,用于apply指定
|
|
34
|
-
* @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
|
|
35
|
-
* @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
|
|
36
|
-
*/
|
|
37
|
-
run<A extends any[], R>(
|
|
38
|
-
callback: ((...args: A) => R) | string | ((...args: any[]) => any),
|
|
39
|
-
__context__?: any
|
|
40
|
-
): UtilsTryCatchType {
|
|
41
|
-
callbackFunction = callback;
|
|
42
|
-
context = __context__ || this;
|
|
43
|
-
const result = executeTryCatch(callbackFunction, handleError, context);
|
|
44
|
-
return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
50
|
-
* @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
51
|
-
* @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
52
|
-
* @param funcThis - 待执行函数的作用域,用于apply指定
|
|
53
|
-
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
54
|
-
*/
|
|
55
|
-
function executeTryCatch<A extends any[], R>(
|
|
56
|
-
callback: string | ((...args: A) => R) | ((...args: any[]) => any),
|
|
57
|
-
handleErrorFunc: string | ((...args: any[]) => any),
|
|
58
|
-
funcThis?: any
|
|
59
|
-
) {
|
|
60
|
-
let result = void 0;
|
|
61
|
-
try {
|
|
62
|
-
if (typeof callback === "string") {
|
|
63
|
-
result = new Function(callback).apply(funcThis, args);
|
|
64
|
-
} else {
|
|
65
|
-
result = (callback as (...args: any[]) => any).apply(funcThis, args);
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
if (defaultDetails.log) {
|
|
69
|
-
callback = callback as (...args: any[]) => any;
|
|
70
|
-
console.log(`%c ${callback?.name ? callback?.name : `${callback}`} `, "color: #f20000");
|
|
71
|
-
console.log(`%c ${error}`, "color: #f20000");
|
|
72
|
-
console.trace(callback);
|
|
73
|
-
}
|
|
74
|
-
if (handleErrorFunc) {
|
|
75
|
-
if (typeof handleErrorFunc === "string") {
|
|
76
|
-
result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
|
|
77
|
-
} else {
|
|
78
|
-
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return TryCatchCore;
|
|
86
|
-
};
|
|
1
|
+
import type { UtilsTryCatchConfig, UtilsTryCatchType } from "./types/TryCatch";
|
|
2
|
+
|
|
3
|
+
export const TryCatch = function (...args: any) {
|
|
4
|
+
/* 定义变量和函数 */
|
|
5
|
+
let callbackFunction = null;
|
|
6
|
+
let context = null;
|
|
7
|
+
let handleError: (error: Error) => void = () => {};
|
|
8
|
+
let defaultDetails = {
|
|
9
|
+
log: true,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const TryCatchCore = {
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param paramDetails 配置
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
config(paramDetails: UtilsTryCatchConfig) {
|
|
19
|
+
defaultDetails = Object.assign(defaultDetails, paramDetails);
|
|
20
|
+
return TryCatchCore;
|
|
21
|
+
},
|
|
22
|
+
/**
|
|
23
|
+
* 处理错误
|
|
24
|
+
* @param handler
|
|
25
|
+
*/
|
|
26
|
+
error(handler: ((...args: any[]) => any) | string | ((...args: any[]) => any)) {
|
|
27
|
+
handleError = handler as (error: Error) => void;
|
|
28
|
+
return TryCatchCore;
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
32
|
+
* @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
33
|
+
* @param __context__ 待执行函数的作用域,用于apply指定
|
|
34
|
+
* @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
|
|
35
|
+
* @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
|
|
36
|
+
*/
|
|
37
|
+
run<A extends any[], R>(
|
|
38
|
+
callback: ((...args: A) => R) | string | ((...args: any[]) => any),
|
|
39
|
+
__context__?: any
|
|
40
|
+
): UtilsTryCatchType {
|
|
41
|
+
callbackFunction = callback;
|
|
42
|
+
context = __context__ || this;
|
|
43
|
+
const result = executeTryCatch(callbackFunction, handleError, context);
|
|
44
|
+
return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
50
|
+
* @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
51
|
+
* @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
|
|
52
|
+
* @param funcThis - 待执行函数的作用域,用于apply指定
|
|
53
|
+
* @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
|
|
54
|
+
*/
|
|
55
|
+
function executeTryCatch<A extends any[], R>(
|
|
56
|
+
callback: string | ((...args: A) => R) | ((...args: any[]) => any),
|
|
57
|
+
handleErrorFunc: string | ((...args: any[]) => any),
|
|
58
|
+
funcThis?: any
|
|
59
|
+
) {
|
|
60
|
+
let result = void 0;
|
|
61
|
+
try {
|
|
62
|
+
if (typeof callback === "string") {
|
|
63
|
+
result = new Function(callback).apply(funcThis, args);
|
|
64
|
+
} else {
|
|
65
|
+
result = (callback as (...args: any[]) => any).apply(funcThis, args);
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (defaultDetails.log) {
|
|
69
|
+
callback = callback as (...args: any[]) => any;
|
|
70
|
+
console.log(`%c ${callback?.name ? callback?.name : `${callback}`} `, "color: #f20000");
|
|
71
|
+
console.log(`%c ${error}`, "color: #f20000");
|
|
72
|
+
console.trace(callback);
|
|
73
|
+
}
|
|
74
|
+
if (handleErrorFunc) {
|
|
75
|
+
if (typeof handleErrorFunc === "string") {
|
|
76
|
+
result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
|
|
77
|
+
} else {
|
|
78
|
+
result = handleErrorFunc.apply(funcThis, [...args, error]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return TryCatchCore;
|
|
86
|
+
};
|