@whitesev/utils 2.6.8 → 2.7.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.
@@ -0,0 +1,287 @@
1
+ import type { WindowApiOption } from "./types/WindowApi";
2
+ import { WindowApi } from "./WindowApi";
3
+
4
+ class DOMUtils {
5
+ private windowApi: typeof WindowApi.prototype;
6
+ constructor(option?: WindowApiOption) {
7
+ this.windowApi = new WindowApi(option);
8
+ }
9
+ /**
10
+ * 选择器,可使用以下的额外语法
11
+ *
12
+ * + :contains([text]) 作用: 找到包含指定文本内容的指定元素
13
+ * + :empty 作用:找到既没有文本内容也没有子元素的指定元素
14
+ * + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
15
+ * @param selector 选择器
16
+ * @param parent 指定父元素
17
+ * @example
18
+ * DOMUtils.selector("div:contains('测试')")
19
+ * > div.xxx
20
+ * @example
21
+ * DOMUtils.selector("div:empty")
22
+ * > div.xxx
23
+ * @example
24
+ * DOMUtils.selector("div:regexp('^xxxx$')")
25
+ * > div.xxx
26
+ */
27
+ selector<K extends keyof HTMLElementTagNameMap>(
28
+ selector: K,
29
+ parent?: Element | Document | DocumentFragment | ShadowRoot
30
+ ): HTMLElementTagNameMap[K] | undefined;
31
+ selector<E extends Element = Element>(
32
+ selector: string,
33
+ parent?: Element | Document | DocumentFragment | ShadowRoot
34
+ ): E | undefined;
35
+ selector<E extends Element = Element>(
36
+ selector: string,
37
+ parent?: Element | Document | DocumentFragment | ShadowRoot
38
+ ) {
39
+ return this.selectorAll<E>(selector, parent)[0];
40
+ }
41
+ /**
42
+ * 选择器,可使用以下的额外语法
43
+ *
44
+ * + :contains([text]) 作用: 找到包含指定文本内容的指定元素
45
+ * + :empty 作用:找到既没有文本内容也没有子元素的指定元素
46
+ * + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
47
+ * @param selector 选择器
48
+ * @param parent 指定父元素
49
+ * @example
50
+ * DOMUtils.selectorAll("div:contains('测试')")
51
+ * > [div.xxx]
52
+ * @example
53
+ * DOMUtils.selectorAll("div:empty")
54
+ * > [div.xxx]
55
+ * @example
56
+ * DOMUtils.selectorAll("div:regexp('^xxxx$')")
57
+ * > [div.xxx]
58
+ * @example
59
+ * DOMUtils.selectorAll("div:regexp(/^xxx/ig)")
60
+ * > [div.xxx]
61
+ */
62
+ selectorAll<K extends keyof HTMLElementTagNameMap>(
63
+ selector: K,
64
+ parent?: Element | Document | DocumentFragment | ShadowRoot
65
+ ): HTMLElementTagNameMap[K][];
66
+ selectorAll<E extends Element = Element>(
67
+ selector: string,
68
+ parent?: Element | Document | DocumentFragment | ShadowRoot
69
+ ): E[];
70
+ selectorAll<E extends Element = Element>(
71
+ selector: string,
72
+ parent?: Element | Document | DocumentFragment | ShadowRoot
73
+ ) {
74
+ const context = this;
75
+ parent = parent || context.windowApi.document;
76
+ selector = selector.trim();
77
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
78
+ // empty 语法
79
+ selector = selector.replace(/:empty$/gi, "");
80
+ return Array.from(parent.querySelectorAll<E>(selector)).filter(($ele) => {
81
+ return $ele?.innerHTML?.trim() === "";
82
+ });
83
+ } else if (
84
+ selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
85
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)
86
+ ) {
87
+ // contains 语法
88
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
89
+ let text = textMatch![2];
90
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
91
+ return Array.from(parent.querySelectorAll<E>(selector)).filter(($ele) => {
92
+ // @ts-ignore
93
+ return ($ele?.textContent || $ele?.innerText)?.includes(text);
94
+ });
95
+ } else if (
96
+ selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
97
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)
98
+ ) {
99
+ // regexp 语法
100
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
101
+ let pattern = textMatch![2];
102
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
103
+ let flags = "";
104
+ if (flagMatch) {
105
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
106
+ flags = flagMatch[3];
107
+ }
108
+ let regexp = new RegExp(pattern, flags);
109
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
110
+ return Array.from(parent.querySelectorAll<E>(selector)).filter(($ele) => {
111
+ // @ts-ignore
112
+ return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
113
+ });
114
+ } else {
115
+ // 普通语法
116
+ return Array.from(parent.querySelectorAll<E>(selector));
117
+ }
118
+ }
119
+ /**
120
+ * 匹配元素,可使用以下的额外语法
121
+ *
122
+ * + :contains([text]) 作用: 找到包含指定文本内容的指定元素
123
+ * + :empty 作用:找到既没有文本内容也没有子元素的指定元素
124
+ * + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
125
+ * @param $el 元素
126
+ * @param selector 选择器
127
+ * @example
128
+ * DOMUtils.matches("div:contains('测试')")
129
+ * > true
130
+ * @example
131
+ * DOMUtils.matches("div:empty")
132
+ * > true
133
+ * @example
134
+ * DOMUtils.matches("div:regexp('^xxxx$')")
135
+ * > true
136
+ * @example
137
+ * DOMUtils.matches("div:regexp(/^xxx/ig)")
138
+ * > false
139
+ */
140
+ matches(
141
+ $el: HTMLElement | Element | null | undefined,
142
+ selector: string
143
+ ): boolean {
144
+ selector = selector.trim();
145
+ if ($el == null) {
146
+ return false;
147
+ }
148
+
149
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
150
+ // empty 语法
151
+ selector = selector.replace(/:empty$/gi, "");
152
+ return $el.matches(selector) && $el?.innerHTML?.trim() === "";
153
+ } else if (
154
+ selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
155
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)
156
+ ) {
157
+ // contains 语法
158
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
159
+ let text = textMatch![2];
160
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
161
+ // @ts-ignore
162
+ let content = $el?.textContent || $el?.innerText;
163
+ if (typeof content !== "string") {
164
+ content = "";
165
+ }
166
+ return $el.matches(selector) && content?.includes(text);
167
+ } else if (
168
+ selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
169
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)
170
+ ) {
171
+ // regexp 语法
172
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
173
+ let pattern = textMatch![2];
174
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
175
+ let flags = "";
176
+ if (flagMatch) {
177
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
178
+ flags = flagMatch[3];
179
+ }
180
+ let regexp = new RegExp(pattern, flags);
181
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
182
+ // @ts-ignore
183
+ let content = $el?.textContent || $el?.innerText;
184
+ if (typeof content !== "string") {
185
+ content = "";
186
+ }
187
+ return $el.matches(selector) && Boolean(content?.match(regexp));
188
+ } else {
189
+ // 普通语法
190
+ return $el.matches(selector);
191
+ }
192
+ }
193
+ /**
194
+ * 根据选择器获取上层元素,可使用以下的额外语法
195
+ *
196
+ * + :contains([text]) 作用: 找到包含指定文本内容的指定元素
197
+ * + :empty 作用:找到既没有文本内容也没有子元素的指定元素
198
+ * + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
199
+ * @param $el 元素
200
+ * @param selector 选择器
201
+ * @example
202
+ * DOMUtils.closest("div:contains('测试')")
203
+ * > div.xxx
204
+ * @example
205
+ * DOMUtils.closest("div:empty")
206
+ * > div.xxx
207
+ * @example
208
+ * DOMUtils.closest("div:regexp('^xxxx$')")
209
+ * > div.xxxx
210
+ * @example
211
+ * DOMUtils.closest("div:regexp(/^xxx/ig)")
212
+ * > null
213
+ */
214
+ closest<K extends keyof HTMLElementTagNameMap>(
215
+ $el: HTMLElement | Element,
216
+ selector: string
217
+ ): HTMLElementTagNameMap[K] | null;
218
+ closest<E extends Element = Element>(
219
+ $el: HTMLElement | Element,
220
+ selector: string
221
+ ): E | null;
222
+ closest<E extends Element = Element>(
223
+ $el: HTMLElement | Element,
224
+ selector: string
225
+ ): E | null {
226
+ selector = selector.trim();
227
+
228
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
229
+ // empty 语法
230
+ selector = selector.replace(/:empty$/gi, "");
231
+ let $closest = $el?.closest<E>(selector);
232
+ if ($closest && $closest?.innerHTML?.trim() === "") {
233
+ return $closest;
234
+ }
235
+ return null;
236
+ } else if (
237
+ selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
238
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)
239
+ ) {
240
+ // contains 语法
241
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
242
+ let text = textMatch![2];
243
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
244
+ let $closest = $el?.closest<E>(selector);
245
+ if ($closest) {
246
+ // @ts-ignore
247
+ let content = $el?.textContent || $el?.innerText;
248
+ if (typeof content === "string" && content.includes(text)) {
249
+ return $closest;
250
+ }
251
+ }
252
+ return null;
253
+ } else if (
254
+ selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
255
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)
256
+ ) {
257
+ // regexp 语法
258
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
259
+ let pattern = textMatch![2];
260
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
261
+ let flags = "";
262
+ if (flagMatch) {
263
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
264
+ flags = flagMatch[3];
265
+ }
266
+ let regexp = new RegExp(pattern, flags);
267
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
268
+ let $closest = $el?.closest<E>(selector);
269
+ if ($closest) {
270
+ // @ts-ignore
271
+ let content = $el?.textContent || $el?.innerText;
272
+ if (typeof content === "string" && content.match(regexp)) {
273
+ return $closest;
274
+ }
275
+ }
276
+ return null;
277
+ } else {
278
+ // 普通语法
279
+ let $closest = $el?.closest<E>(selector);
280
+ return $closest;
281
+ }
282
+ }
283
+ }
284
+
285
+ let domUtils = new DOMUtils();
286
+
287
+ export { domUtils };
package/src/Dictionary.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Utils } from "./Utils";
1
+ import { CommonUtil } from "./CommonUtil";
2
2
 
3
3
  class UtilsDictionary<K, V> {
4
4
  private items: {
@@ -120,7 +120,7 @@ class UtilsDictionary<K, V> {
120
120
  * @param data 需要合并的字典
121
121
  */
122
122
  concat(data: UtilsDictionary<K, V>) {
123
- this.items = Utils.assign(this.items, data.getItems());
123
+ this.items = CommonUtil.assign(this.items, data.getItems());
124
124
  }
125
125
  forEach(
126
126
  callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void
package/src/Hooks.ts CHANGED
@@ -33,18 +33,17 @@ class Hooks {
33
33
  return "";
34
34
  }
35
35
  try {
36
- eval(
37
- "_context[_funcName] = function " +
38
- _funcName +
39
- "(){\n" +
40
- "let args = Array.prototype.slice.call(arguments,0);\n" +
41
- "let obj = this;\n" +
42
- "hookFunc.apply(obj,args);\n" +
43
- "return _context['realFunc_" +
44
- _funcName +
45
- "'].apply(obj,args);\n" +
46
- "};"
47
- );
36
+ new Function(
37
+ "_context",
38
+ "_funcName",
39
+ "hookFunc",
40
+ `_context[_funcName] = function ${_funcName}() {
41
+ let args = Array.prototype.slice.call(arguments, 0);
42
+ let obj = this;
43
+ hookFunc.apply(obj, args);
44
+ return _context['realFunc_${_funcName}'].apply(obj, args);
45
+ };`
46
+ )(_context, _funcName, hookFunc);
48
47
  (_context as any)[_funcName].prototype.isHooked = true;
49
48
  return true;
50
49
  } catch (e) {
package/src/Httpx.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { CommonUtil } from "./CommonUtil";
2
+ import { TryCatch } from "./TryCatch";
1
3
  import type {
2
4
  HttpxAllowInterceptConfig,
3
5
  HttpxHookErrorData,
@@ -8,7 +10,6 @@ import type {
8
10
  HttpxPromise,
9
11
  HttpxInitOption,
10
12
  } from "./types/Httpx";
11
- import { Utils } from "./Utils";
12
13
  import { GenerateUUID } from "./UtilsCommon";
13
14
 
14
15
  class Httpx {
@@ -250,13 +251,13 @@ class Httpx {
250
251
  if (typeof args[1] === "object") {
251
252
  /* 处理第二个参数details */
252
253
  let optionArg = args[1];
253
- Utils.assign(option, optionArg, true);
254
+ CommonUtil.assign(option, optionArg, true);
254
255
  option.url = url;
255
256
  }
256
257
  } else {
257
258
  /* 传入的是配置 */
258
259
  let optionArg = args[0];
259
- Utils.assign(option, optionArg, true);
260
+ CommonUtil.assign(option, optionArg, true);
260
261
  }
261
262
  return option;
262
263
  },
@@ -297,7 +298,9 @@ class Httpx {
297
298
  userRequestOption.responseType ||
298
299
  this.context.#defaultRequestOption.responseType,
299
300
  /* 对象使用深拷贝 */
300
- headers: Utils.deepClone(this.context.#defaultRequestOption.headers),
301
+ headers: CommonUtil.deepClone(
302
+ this.context.#defaultRequestOption.headers
303
+ ),
301
304
  data: userRequestOption.data || this.context.#defaultRequestOption.data,
302
305
  redirect:
303
306
  userRequestOption.redirect ||
@@ -316,7 +319,7 @@ class Httpx {
316
319
  userRequestOption.revalidate ||
317
320
  this.context.#defaultRequestOption.revalidate,
318
321
  /* 对象使用深拷贝 */
319
- context: Utils.deepClone(
322
+ context: CommonUtil.deepClone(
320
323
  userRequestOption.context ||
321
324
  this.context.#defaultRequestOption.context
322
325
  ),
@@ -329,7 +332,7 @@ class Httpx {
329
332
  fetch:
330
333
  userRequestOption.fetch || this.context.#defaultRequestOption.fetch,
331
334
  /* 对象使用深拷贝 */
332
- fetchInit: Utils.deepClone(
335
+ fetchInit: CommonUtil.deepClone(
333
336
  this.context.#defaultRequestOption.fetchInit
334
337
  ),
335
338
  allowInterceptConfig: {
@@ -627,13 +630,13 @@ class Httpx {
627
630
  if (
628
631
  option[keyName as keyof HttpxRequestOption] == null ||
629
632
  (option[keyName as keyof HttpxRequestOption] instanceof Function &&
630
- Utils.isNull(option[keyName as keyof HttpxRequestOption]))
633
+ CommonUtil.isNull(option[keyName as keyof HttpxRequestOption]))
631
634
  ) {
632
635
  Reflect.deleteProperty(option, keyName);
633
636
  return;
634
637
  }
635
638
  });
636
- if (Utils.isNull(option.url)) {
639
+ if (CommonUtil.isNull(option.url)) {
637
640
  throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
638
641
  }
639
642
  return option;
@@ -861,11 +864,11 @@ class Httpx {
861
864
  let originResponse: HttpxResponseData<HttpxRequestOption> = argsResult[0];
862
865
  /* responseText为空,response不为空的情况 */
863
866
  if (
864
- Utils.isNull(originResponse["responseText"]) &&
865
- Utils.isNotNull(originResponse["response"])
867
+ CommonUtil.isNull(originResponse["responseText"]) &&
868
+ CommonUtil.isNotNull(originResponse["response"])
866
869
  ) {
867
870
  if (typeof originResponse["response"] === "object") {
868
- Utils.tryCatch().run(() => {
871
+ TryCatch().run(() => {
869
872
  originResponse["responseText"] = JSON.stringify(
870
873
  originResponse["response"]
871
874
  );
@@ -886,7 +889,7 @@ class Httpx {
886
889
  // 自定义个新的response
887
890
  let httpxResponse: any = httpxResponseText;
888
891
  if (details.responseType === "json") {
889
- httpxResponse = Utils.toJSON(httpxResponseText);
892
+ httpxResponse = CommonUtil.toJSON(httpxResponseText);
890
893
  } else if (details.responseType === "document") {
891
894
  let parser = new DOMParser();
892
895
  httpxResponse = parser.parseFromString(
@@ -1139,7 +1142,7 @@ class Httpx {
1139
1142
  fetchResponseType.includes("application/json"))
1140
1143
  ) {
1141
1144
  // response返回格式是JSON格式
1142
- response = Utils.toJSON(responseText);
1145
+ response = CommonUtil.toJSON(responseText);
1143
1146
  } else if (
1144
1147
  option.responseType === "document" ||
1145
1148
  option.responseType == null
@@ -1245,7 +1248,7 @@ class Httpx {
1245
1248
  "[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch"
1246
1249
  );
1247
1250
  }
1248
- Utils.coverObjectFunctionThis(this);
1251
+ CommonUtil.coverObjectFunctionThis(this);
1249
1252
  this.interceptors.request.context = this;
1250
1253
  this.interceptors.response.context = this;
1251
1254
  this.config(option);
@@ -1258,11 +1261,14 @@ class Httpx {
1258
1261
  if (typeof option.xmlHttpRequest === "function") {
1259
1262
  this.GM_Api.xmlHttpRequest = option.xmlHttpRequest;
1260
1263
  }
1261
- this.#defaultRequestOption = Utils.assign(
1264
+ this.#defaultRequestOption = CommonUtil.assign(
1262
1265
  this.#defaultRequestOption,
1263
1266
  option
1264
1267
  );
1265
- this.#defaultInitOption = Utils.assign(this.#defaultInitOption, option);
1268
+ this.#defaultInitOption = CommonUtil.assign(
1269
+ this.#defaultInitOption,
1270
+ option
1271
+ );
1266
1272
  }
1267
1273
  /**
1268
1274
  * 拦截器
@@ -1,10 +1,8 @@
1
- import { Utils } from "./Utils";
2
-
3
1
  class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
4
2
  #flag: boolean = false;
5
3
  #delayTime: number = 0;
6
4
  #callback: K;
7
- #context: typeof Utils;
5
+ #timeId: number | undefined = void 0;
8
6
  lock: () => void;
9
7
  unlock: () => void;
10
8
  run: (...args: any[]) => Promise<void>;
@@ -25,22 +23,21 @@ class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
25
23
  this.#callback = callback;
26
24
  if (typeof context === "number") {
27
25
  this.#delayTime = context;
28
- this.#context = Utils;
29
26
  } else {
30
27
  this.#delayTime = delayTime as number;
31
- this.#context = context;
32
28
  }
33
29
  /**
34
30
  * 锁
35
31
  */
36
32
  this.lock = function () {
37
33
  that.#flag = true;
34
+ clearTimeout(that.#timeId);
38
35
  };
39
36
  /**
40
37
  * 解锁
41
38
  */
42
39
  this.unlock = function () {
43
- Utils.workerSetTimeout(() => {
40
+ that.#timeId = setTimeout(() => {
44
41
  that.#flag = false;
45
42
  }, that.#delayTime);
46
43
  };
@@ -58,7 +55,7 @@ class LockFunction<K extends (...args: any[]) => any | Promise<any> | void> {
58
55
  return;
59
56
  }
60
57
  that.lock();
61
- await that.#callback.apply(that.#context, args);
58
+ await that.#callback.apply(this, args);
62
59
  that.unlock();
63
60
  };
64
61
  }
package/src/Progress.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { CommonUtil } from "./CommonUtil";
1
2
  import type { ProgressParamConfig } from "./types/Progress";
2
- import { Utils } from "./Utils";
3
3
 
4
4
  class Progress {
5
5
  #config: ProgressParamConfig = {
@@ -48,7 +48,7 @@ class Progress {
48
48
  * @param paramConfig 配置信息
49
49
  */
50
50
  constructor(paramConfig: ProgressParamConfig) {
51
- this.#config = Utils.assign(this.#config, paramConfig);
51
+ this.#config = CommonUtil.assign(this.#config, paramConfig);
52
52
  if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
53
53
  throw new Error(
54
54
  "Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement"
package/src/TryCatch.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { UtilsTryCatchConfig, UtilsTryCatchType } from "./types/TryCatch";
2
- import { Utils } from "./Utils";
3
2
 
4
3
  export const TryCatch = function (...args: any) {
5
4
  /* 定义变量和函数 */
@@ -17,7 +16,7 @@ export const TryCatch = function (...args: any) {
17
16
  * @returns
18
17
  */
19
18
  config(paramDetails: UtilsTryCatchConfig) {
20
- defaultDetails = Utils.assign(defaultDetails, paramDetails);
19
+ defaultDetails = Object.assign(defaultDetails, paramDetails);
21
20
  return TryCatchCore;
22
21
  },
23
22
  /**
@@ -63,9 +62,7 @@ export const TryCatch = function (...args: any) {
63
62
  let result = void 0;
64
63
  try {
65
64
  if (typeof callback === "string") {
66
- (function () {
67
- eval(callback as string);
68
- }).apply(funcThis, args);
65
+ result = new Function(callback).apply(funcThis, args);
69
66
  } else {
70
67
  result = (callback as Function).apply(funcThis, args);
71
68
  }
@@ -81,10 +78,10 @@ export const TryCatch = function (...args: any) {
81
78
  }
82
79
  if (handleErrorFunc) {
83
80
  if (typeof handleErrorFunc === "string") {
84
- result = function () {
85
- return eval(handleErrorFunc);
86
- // @ts-ignore
87
- }.apply(funcThis, [...args, error]);
81
+ result = new Function(handleErrorFunc).apply(funcThis, [
82
+ ...args,
83
+ error,
84
+ ]);
88
85
  } else {
89
86
  result = handleErrorFunc.apply(funcThis, [...args, error]);
90
87
  }