@whitesev/utils 2.7.2 → 2.7.3

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.
@@ -1,6 +1,4 @@
1
- export class LockFunction<
2
- K extends (...args: any[]) => any | Promise<any> | void
3
- > {
1
+ export class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
4
2
  #flag: boolean = false;
5
3
  #delayTime: number = 0;
6
4
  #callback: K;
package/src/Log.ts CHANGED
@@ -45,10 +45,7 @@ export class Log {
45
45
  ) {
46
46
  if (typeof __GM_info === "string") {
47
47
  this.tag = __GM_info;
48
- } else if (
49
- typeof __GM_info === "object" &&
50
- typeof __GM_info?.script?.name === "string"
51
- ) {
48
+ } else if (typeof __GM_info === "object" && typeof __GM_info?.script?.name === "string") {
52
49
  this.tag = __GM_info.script.name;
53
50
  }
54
51
  this.#console = console;
@@ -66,9 +63,7 @@ export class Log {
66
63
  for (let stackString of stack) {
67
64
  stackString = stackString.trim();
68
65
  let stackFunctionNameMatch = stackString.match(/^at[\s]+(.+?)[\s]+/i);
69
- let stackFunctionNamePositionMatch = stackString.match(
70
- /^at[\s]+.+[\s]+\((.+?)\)/i
71
- );
66
+ let stackFunctionNamePositionMatch = stackString.match(/^at[\s]+.+[\s]+\((.+?)\)/i);
72
67
  if (stackFunctionNameMatch == null) {
73
68
  continue;
74
69
  }
@@ -76,12 +71,9 @@ export class Log {
76
71
  continue;
77
72
  }
78
73
  /* 获取最后一个,因为第一个是包含了at */
79
- let stackFunctionName =
80
- stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
74
+ let stackFunctionName = stackFunctionNameMatch[stackFunctionNameMatch.length - 1];
81
75
  let stackFunctionNamePosition =
82
- stackFunctionNamePositionMatch[
83
- stackFunctionNamePositionMatch.length - 1
84
- ];
76
+ stackFunctionNamePositionMatch[stackFunctionNamePositionMatch.length - 1];
85
77
  if (
86
78
  stackFunctionName === "" ||
87
79
  stackFunctionName.match(
@@ -114,10 +106,7 @@ export class Log {
114
106
  */
115
107
  private checkClearConsole() {
116
108
  this.#logCount++;
117
- if (
118
- this.#details.autoClearConsole &&
119
- this.#logCount > this.#details.logMaxCount
120
- ) {
109
+ if (this.#details.autoClearConsole && this.#logCount > this.#details.logMaxCount) {
121
110
  this.#console.clear();
122
111
  this.#logCount = 0;
123
112
  }
@@ -134,8 +123,7 @@ export class Log {
134
123
  otherStyle = otherStyle || "";
135
124
  let stackSplit = new Error()!.stack!.split("\n");
136
125
  stackSplit.splice(0, 2);
137
- let { name: callerName, position: callerPosition } =
138
- this.parseErrorStack(stackSplit);
126
+ let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
139
127
  let tagName = this.tag;
140
128
  let that = this;
141
129
 
@@ -204,11 +192,7 @@ export class Log {
204
192
  */
205
193
  warn(...args: any[]) {
206
194
  if (this.#disable) return;
207
- this.printContent(
208
- args,
209
- this.#details.warnColor,
210
- "background: #FEF6D5;padding: 4px 6px 4px 0px;"
211
- );
195
+ this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
212
196
  }
213
197
  /**
214
198
  * 控制台-错误输出
package/src/Progress.ts CHANGED
@@ -50,9 +50,7 @@ export class Progress {
50
50
  constructor(paramConfig: ProgressParamConfig) {
51
51
  this.#config = CommonUtil.assign(this.#config, paramConfig);
52
52
  if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
53
- throw new Error(
54
- "Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement"
55
- );
53
+ throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
56
54
  }
57
55
  this.init();
58
56
  }
@@ -90,13 +88,7 @@ export class Progress {
90
88
  this.#ctx.clearRect(0, 0, this.#width, this.#height);
91
89
  /* 开始绘制底圆 */
92
90
  this.#ctx.beginPath();
93
- this.#ctx.arc(
94
- this.#width / 2,
95
- this.#height / 2,
96
- this.#config.circleRadius,
97
- 1,
98
- 8
99
- );
91
+ this.#ctx.arc(this.#width / 2, this.#height / 2, this.#config.circleRadius, 1, 8);
100
92
  this.#ctx.strokeStyle = this.#config.lineBgColor;
101
93
  this.#ctx.stroke();
102
94
  /* 开始绘制动态圆 */
package/src/TryCatch.ts CHANGED
@@ -41,9 +41,7 @@ export const TryCatch = function (...args: any) {
41
41
  callbackFunction = callback;
42
42
  context = __context__ || this;
43
43
  let result = executeTryCatch(callbackFunction, handleError, context);
44
- return result !== void 0
45
- ? result
46
- : (TryCatchCore as any as UtilsTryCatchType);
44
+ return result !== void 0 ? result : (TryCatchCore as any as UtilsTryCatchType);
47
45
  },
48
46
  };
49
47
 
@@ -69,19 +67,13 @@ export const TryCatch = function (...args: any) {
69
67
  } catch (error) {
70
68
  if (defaultDetails.log) {
71
69
  callback = callback as Function;
72
- console.log(
73
- `%c ${callback?.name ? callback?.name : callback + "出现错误"} `,
74
- "color: #f20000"
75
- );
70
+ console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
76
71
  console.log(`%c 错误原因:${error}`, "color: #f20000");
77
72
  console.trace(callback);
78
73
  }
79
74
  if (handleErrorFunc) {
80
75
  if (typeof handleErrorFunc === "string") {
81
- result = new Function(handleErrorFunc).apply(funcThis, [
82
- ...args,
83
- error,
84
- ]);
76
+ result = new Function(handleErrorFunc).apply(funcThis, [...args, error]);
85
77
  } else {
86
78
  result = handleErrorFunc.apply(funcThis, [...args, error]);
87
79
  }