@whitesev/utils 2.9.11 → 2.9.13

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 (73) hide show
  1. package/README.md +176 -176
  2. package/dist/index.amd.js +159 -101
  3. package/dist/index.amd.js.map +1 -1
  4. package/dist/index.amd.min.js +1 -1
  5. package/dist/index.amd.min.js.map +1 -1
  6. package/dist/index.cjs.js +159 -101
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.cjs.min.js +1 -1
  9. package/dist/index.cjs.min.js.map +1 -1
  10. package/dist/index.esm.js +159 -101
  11. package/dist/index.esm.js.map +1 -1
  12. package/dist/index.esm.min.js +1 -1
  13. package/dist/index.esm.min.js.map +1 -1
  14. package/dist/index.iife.js +159 -101
  15. package/dist/index.iife.js.map +1 -1
  16. package/dist/index.iife.min.js +1 -1
  17. package/dist/index.iife.min.js.map +1 -1
  18. package/dist/index.system.js +159 -101
  19. package/dist/index.system.js.map +1 -1
  20. package/dist/index.system.min.js +1 -1
  21. package/dist/index.system.min.js.map +1 -1
  22. package/dist/index.umd.js +159 -101
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/index.umd.min.js +1 -1
  25. package/dist/index.umd.min.js.map +1 -1
  26. package/dist/types/src/Dictionary.d.ts +2 -0
  27. package/dist/types/src/Utils.d.ts +5 -2
  28. package/dist/types/src/types/Httpx.d.ts +1344 -1344
  29. package/dist/types/src/types/Log.d.ts +19 -19
  30. package/dist/types/src/types/Progress.d.ts +20 -20
  31. package/dist/types/src/types/React.d.ts +119 -119
  32. package/dist/types/src/types/TryCatch.d.ts +9 -9
  33. package/dist/types/src/types/UtilsGMCookie.d.ts +93 -93
  34. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -77
  35. package/dist/types/src/types/Vue2.d.ts +166 -166
  36. package/dist/types/src/types/WindowApi.d.ts +14 -14
  37. package/dist/types/src/types/ajaxHooker.d.ts +155 -155
  38. package/dist/types/src/types/env.d.ts +7 -7
  39. package/dist/types/src/types/global.d.ts +31 -31
  40. package/package.json +26 -24
  41. package/src/ColorConversion.ts +118 -118
  42. package/src/CommonUtil.ts +301 -285
  43. package/src/DOMUtils.ts +251 -251
  44. package/src/Dictionary.ts +205 -199
  45. package/src/GBKEncoder.ts +108 -108
  46. package/src/Hooks.ts +73 -73
  47. package/src/Httpx.ts +1457 -1457
  48. package/src/LockFunction.ts +65 -62
  49. package/src/Log.ts +233 -233
  50. package/src/ModuleRaid.js +378 -360
  51. package/src/Progress.ts +108 -108
  52. package/src/TryCatch.ts +86 -86
  53. package/src/Utils.ts +3860 -3852
  54. package/src/UtilsCommon.ts +14 -14
  55. package/src/UtilsGMCookie.ts +273 -273
  56. package/src/UtilsGMMenu.ts +460 -460
  57. package/src/Vue.ts +233 -233
  58. package/src/WindowApi.ts +59 -59
  59. package/src/ajaxHooker/ajaxHooker.js +606 -538
  60. package/src/ajaxHooker/ajaxHooker1.2.4.js +440 -438
  61. package/src/indexedDB.ts +497 -497
  62. package/src/types/Httpx.d.ts +1344 -1344
  63. package/src/types/Log.d.ts +19 -19
  64. package/src/types/Progress.d.ts +20 -20
  65. package/src/types/React.d.ts +119 -119
  66. package/src/types/TryCatch.d.ts +9 -9
  67. package/src/types/UtilsGMCookie.d.ts +93 -93
  68. package/src/types/UtilsGMMenu.d.ts +77 -77
  69. package/src/types/Vue2.d.ts +166 -166
  70. package/src/types/WindowApi.d.ts +14 -14
  71. package/src/types/ajaxHooker.d.ts +155 -155
  72. package/src/types/env.d.ts +7 -7
  73. package/src/types/global.d.ts +31 -31
package/dist/index.amd.js CHANGED
@@ -57,47 +57,7 @@ define((function () { 'use strict';
57
57
  const cache = createCache(LAST_NUMBER_WEAK_MAP);
58
58
  const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
59
59
 
60
- const isMessagePort = (sender) => {
61
- return typeof sender.start === 'function';
62
- };
63
-
64
- const PORT_MAP = new WeakMap();
65
-
66
- const extendBrokerImplementation = (partialBrokerImplementation) => ({
67
- ...partialBrokerImplementation,
68
- connect: ({ call }) => {
69
- return async () => {
70
- const { port1, port2 } = new MessageChannel();
71
- const portId = await call('connect', { port: port1 }, [port1]);
72
- PORT_MAP.set(port2, portId);
73
- return port2;
74
- };
75
- },
76
- disconnect: ({ call }) => {
77
- return async (port) => {
78
- const portId = PORT_MAP.get(port);
79
- if (portId === undefined) {
80
- throw new Error('The given port is not connected.');
81
- }
82
- await call('disconnect', { portId });
83
- };
84
- },
85
- isSupported: ({ call }) => {
86
- return () => call('isSupported');
87
- }
88
- });
89
-
90
- const ONGOING_REQUESTS = new WeakMap();
91
- const createOrGetOngoingRequests = (sender) => {
92
- if (ONGOING_REQUESTS.has(sender)) {
93
- // @todo TypeScript needs to be convinced that has() works as expected.
94
- return ONGOING_REQUESTS.get(sender);
95
- }
96
- const ongoingRequests = new Map();
97
- ONGOING_REQUESTS.set(sender, ongoingRequests);
98
- return ongoingRequests;
99
- };
100
- const createBroker = (brokerImplementation) => {
60
+ const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
101
61
  const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
102
62
  return (sender) => {
103
63
  const ongoingRequests = createOrGetOngoingRequests(sender);
@@ -140,6 +100,46 @@ define((function () { 'use strict';
140
100
  };
141
101
  };
142
102
 
103
+ const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
104
+ if (ongoingRequestsMap.has(sender)) {
105
+ // @todo TypeScript needs to be convinced that has() works as expected.
106
+ return ongoingRequestsMap.get(sender);
107
+ }
108
+ const ongoingRequests = new Map();
109
+ ongoingRequestsMap.set(sender, ongoingRequests);
110
+ return ongoingRequests;
111
+ };
112
+
113
+ const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
114
+ ...partialBrokerImplementation,
115
+ connect: ({ call }) => {
116
+ return async () => {
117
+ const { port1, port2 } = new MessageChannel();
118
+ const portId = await call('connect', { port: port1 }, [port1]);
119
+ portMap.set(port2, portId);
120
+ return port2;
121
+ };
122
+ },
123
+ disconnect: ({ call }) => {
124
+ return async (port) => {
125
+ const portId = portMap.get(port);
126
+ if (portId === undefined) {
127
+ throw new Error('The given port is not connected.');
128
+ }
129
+ await call('disconnect', { portId });
130
+ };
131
+ },
132
+ isSupported: ({ call }) => {
133
+ return () => call('isSupported');
134
+ }
135
+ });
136
+
137
+ const isMessagePort = (sender) => {
138
+ return typeof sender.start === 'function';
139
+ };
140
+
141
+ const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
142
+
143
143
  const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
144
144
  if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
145
145
  scheduledIntervalsState.set(timerId, null);
@@ -231,7 +231,7 @@ define((function () { 'use strict';
231
231
  };
232
232
 
233
233
  // This is the minified and stringified code of the worker-timers-worker package.
234
- const worker = `(()=>{var e={455:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),l=t(c);e.addUniqueNumber=l,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const l=r instanceof Promise?await r:r;if(null===a){if(void 0!==l.result)throw s(i)}else{if(void 0===l.result)throw s(i);const{result:e,transferables:r=[]}=l;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,()=>{n(),t.close(),u.delete(o)}),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise(e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])})){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),l=(e,t,r=()=>!0)=>{const n=c(l,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},d=(e,t)=>r=>{const n=t.get(r);if(void 0===n)return Promise.resolve(!1);const[o,s]=n;return e(o),t.delete(r),s(!1),Promise.resolve(!0)},f=(e,t,r,n)=>(o,s,a)=>{const i=o+s-t.timeOrigin,u=i-t.now();return new Promise(t=>{e.set(a,[r(n,u,i,e,t,a),t])})},m=new Map,h=d(globalThis.clearTimeout,m),p=new Map,v=d(globalThis.clearTimeout,p),w=((e,t)=>{const r=(n,o,s,a)=>{const i=n-e.now();i>0?o.set(a,[t(r,i,n,o,s,a),s]):(o.delete(a),s(!0))};return r})(performance,globalThis.setTimeout),g=f(m,performance,globalThis.setTimeout,w),T=f(p,performance,globalThis.setTimeout,w);l(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?h(e):v(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?g:T)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
234
+ const worker = `(()=>{var e={455(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,s=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<s?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*s);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,u=r(i),c=a(u,i),l=t(c);e.addUniqueNumber=l,e.generateUniqueNumber=c}(t)}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(()=>{"use strict";const e=-32603,t=-32602,n=-32601,o=(e,t)=>Object.assign(new Error(e),{status:t}),s=t=>o('The handler of the method called "'.concat(t,'" returned an unexpected result.'),e),a=(t,r)=>async({data:{id:a,method:i,params:u}})=>{const c=r[i];try{if(void 0===c)throw(e=>o('The requested method called "'.concat(e,'" is not supported.'),n))(i);const r=void 0===u?c():c(u);if(void 0===r)throw(t=>o('The handler of the method called "'.concat(t,'" returned no required result.'),e))(i);const l=r instanceof Promise?await r:r;if(null===a){if(void 0!==l.result)throw s(i)}else{if(void 0===l.result)throw s(i);const{result:e,transferables:r=[]}=l;t.postMessage({id:a,result:e},r)}}catch(e){const{message:r,status:n=-32603}=e;t.postMessage({error:{code:n,message:r},id:a})}};var i=r(455);const u=new Map,c=(e,r,n)=>({...r,connect:({port:t})=>{t.start();const n=e(t,r),o=(0,i.generateUniqueNumber)(u);return u.set(o,()=>{n(),t.close(),u.delete(o)}),{result:o}},disconnect:({portId:e})=>{const r=u.get(e);if(void 0===r)throw(e=>o('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),t))(e);return r(),{result:null}},isSupported:async()=>{if(await new Promise(e=>{const t=new ArrayBuffer(0),{port1:r,port2:n}=new MessageChannel;r.onmessage=({data:t})=>e(null!==t),n.postMessage(t,[t])})){const e=n();return{result:e instanceof Promise?await e:e}}return{result:!1}}}),l=(e,t,r=()=>!0)=>{const n=c(l,t,r),o=a(e,n);return e.addEventListener("message",o),()=>e.removeEventListener("message",o)},d=(e,t)=>r=>{const n=t.get(r);if(void 0===n)return Promise.resolve(!1);const[o,s]=n;return e(o),t.delete(r),s(!1),Promise.resolve(!0)},m=(e,t,r,n)=>(o,s,a)=>{const i=o+s-t.timeOrigin,u=i-t.now();return new Promise(t=>{e.set(a,[r(n,u,i,e,t,a),t])})},f=new Map,h=d(globalThis.clearTimeout,f),p=new Map,v=d(globalThis.clearTimeout,p),w=((e,t)=>{const r=(n,o,s,a)=>{const i=n-e.now();i>0?o.set(a,[t(r,i,n,o,s,a),s]):(o.delete(a),s(!0))};return r})(performance,globalThis.setTimeout),g=m(f,performance,globalThis.setTimeout,w),T=m(p,performance,globalThis.setTimeout,w);l(self,{clear:async({timerId:e,timerType:t})=>({result:await("interval"===t?h(e):v(e))}),set:async({delay:e,now:t,timerId:r,timerType:n})=>({result:await("interval"===n?g:T)(e,t,r)})})})()})();`; // tslint:disable-line:max-line-length
235
235
 
236
236
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
237
237
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -239,7 +239,7 @@ define((function () { 'use strict';
239
239
  const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
240
240
  const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
241
241
 
242
- const version = "2.9.11";
242
+ const version = "2.9.13";
243
243
 
244
244
  /* eslint-disable */
245
245
  // ==UserScript==
@@ -279,7 +279,9 @@ define((function () { 'use strict';
279
279
  const emptyFn = () => { };
280
280
  const errorFn = (e) => console.error(e);
281
281
  function isThenable(obj) {
282
- return obj && ["object", "function"].includes(typeof obj) && typeof obj.then === "function";
282
+ return (obj &&
283
+ ["object", "function"].includes(typeof obj) &&
284
+ typeof obj.then === "function");
283
285
  }
284
286
  function catchError(fn, ...args) {
285
287
  try {
@@ -320,7 +322,8 @@ define((function () { 'use strict';
320
322
  if (!value)
321
323
  continue;
322
324
  const lheader = header.toLowerCase();
323
- headers[lheader] = lheader in headers ? `${headers[lheader]}, ${value}` : value;
325
+ headers[lheader] =
326
+ lheader in headers ? `${headers[lheader]}, ${value}` : value;
324
327
  }
325
328
  break;
326
329
  case "[object Headers]":
@@ -359,9 +362,11 @@ define((function () { 'use strict';
359
362
  !filters.find((obj) => {
360
363
  switch (true) {
361
364
  case obj.type && obj.type !== type:
362
- case getType(obj.url) === "[object String]" && !url.includes(obj.url):
365
+ case getType(obj.url) === "[object String]" &&
366
+ !url.includes(obj.url):
363
367
  case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
364
- case obj.method && obj.method.toUpperCase() !== method.toUpperCase():
368
+ case obj.method &&
369
+ obj.method.toUpperCase() !== method.toUpperCase():
365
370
  case "async" in obj && obj.async !== async:
366
371
  return false;
367
372
  }
@@ -404,7 +409,8 @@ define((function () { 'use strict';
404
409
  if (getType(this.request.response) === "[object Function]") {
405
410
  catchError(this.request.response, response);
406
411
  responseKeys.forEach((key) => {
407
- if ("get" in getDescriptor(response, key) || isThenable(response[key])) {
412
+ if ("get" in getDescriptor(response, key) ||
413
+ isThenable(response[key])) {
408
414
  delete response[key];
409
415
  }
410
416
  });
@@ -425,7 +431,10 @@ define((function () { 'use strict';
425
431
  const proxyHandler = {
426
432
  get(target, prop) {
427
433
  const descriptor = getDescriptor(target, prop);
428
- if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.get)
434
+ if (descriptor &&
435
+ !descriptor.configurable &&
436
+ !descriptor.writable &&
437
+ !descriptor.get)
429
438
  return target[prop];
430
439
  const ah = target.__ajaxHooker;
431
440
  if (ah && ah.proxyProps) {
@@ -444,7 +453,10 @@ define((function () { 'use strict';
444
453
  },
445
454
  set(target, prop, value) {
446
455
  const descriptor = getDescriptor(target, prop);
447
- if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.set)
456
+ if (descriptor &&
457
+ !descriptor.configurable &&
458
+ !descriptor.writable &&
459
+ !descriptor.set)
448
460
  return true;
449
461
  const ah = target.__ajaxHooker;
450
462
  if (ah && ah.proxyProps && prop in ah.proxyProps) {
@@ -468,7 +480,9 @@ define((function () { 'use strict';
468
480
  proxyEvents: {},
469
481
  });
470
482
  xhr.addEventListener("readystatechange", (e) => {
471
- if (ah.proxyXhr.readyState === 4 && ah.request && typeof ah.request.response === "function") {
483
+ if (ah.proxyXhr.readyState === 4 &&
484
+ ah.request &&
485
+ typeof ah.request.response === "function") {
472
486
  const response = {
473
487
  finalUrl: ah.proxyXhr.responseURL,
474
488
  status: ah.proxyXhr.status,
@@ -487,7 +501,9 @@ define((function () { 'use strict';
487
501
  response[key] = val;
488
502
  });
489
503
  }
490
- ah.resThenable = new AHRequest(ah.request).waitForResponseKeys(response).then(() => {
504
+ ah.resThenable = new AHRequest(ah.request)
505
+ .waitForResponseKeys(response)
506
+ .then(() => {
491
507
  for (const key of xhrResponses) {
492
508
  ah.proxyProps[key] = {
493
509
  get: () => {
@@ -510,7 +526,13 @@ define((function () { 'use strict';
510
526
  set: (val) => ah.addEvent(onEvt, val),
511
527
  };
512
528
  }
513
- for (const method of ["setRequestHeader", "addEventListener", "removeEventListener", "open", "send"]) {
529
+ for (const method of [
530
+ "setRequestHeader",
531
+ "addEventListener",
532
+ "removeEventListener",
533
+ "open",
534
+ "send",
535
+ ]) {
514
536
  ah.proxyProps[method] = { value: ah[method] };
515
537
  }
516
538
  }
@@ -557,7 +579,8 @@ define((function () { 'use strict';
557
579
  if (!this.request)
558
580
  return;
559
581
  const headers = this.request.headers;
560
- headers[header] = header in headers ? `${headers[header]}, ${value}` : value;
582
+ headers[header] =
583
+ header in headers ? `${headers[header]}, ${value}` : value;
561
584
  }
562
585
  addEventListener(...args) {
563
586
  if (xhrAsyncEvents.includes(args[0])) {
@@ -588,7 +611,13 @@ define((function () { 'use strict';
588
611
  };
589
612
  this.openArgs = args;
590
613
  this.resThenable = new SyncThenable();
591
- ["responseURL", "readyState", "status", "statusText", ...xhrResponses].forEach((key) => {
614
+ [
615
+ "responseURL",
616
+ "readyState",
617
+ "status",
618
+ "statusText",
619
+ ...xhrResponses,
620
+ ].forEach((key) => {
592
621
  delete this.proxyProps[key];
593
622
  });
594
623
  return this.originalXhr.open(method, url, async, ...args);
@@ -750,13 +779,17 @@ define((function () { 'use strict';
750
779
  // 针对头条、抖音 secsdk.umd.js 的兼容性处理
751
780
  class AHFunction extends Function {
752
781
  call(thisArg, ...args) {
753
- if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
782
+ if (thisArg &&
783
+ thisArg.__ajaxHooker &&
784
+ thisArg.__ajaxHooker.proxyXhr === thisArg) {
754
785
  thisArg = thisArg.__ajaxHooker.originalXhr;
755
786
  }
756
787
  return Reflect.apply(this, thisArg, args);
757
788
  }
758
789
  apply(thisArg, args) {
759
- if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
790
+ if (thisArg &&
791
+ thisArg.__ajaxHooker &&
792
+ thisArg.__ajaxHooker.proxyXhr === thisArg) {
760
793
  thisArg = thisArg.__ajaxHooker.originalXhr;
761
794
  }
762
795
  return Reflect.apply(this, thisArg, args || []);
@@ -1473,40 +1506,55 @@ define((function () { 'use strict';
1473
1506
  isNull(...args) {
1474
1507
  let result = true;
1475
1508
  const checkList = [...args];
1476
- for (const objItem of checkList) {
1477
- let itemResult = false;
1478
- if (objItem === null || objItem === undefined) {
1479
- itemResult = true;
1509
+ for (const obj of checkList) {
1510
+ let flag = false;
1511
+ if (obj === null || obj === undefined) {
1512
+ // null undefined
1513
+ flag = true;
1480
1514
  }
1481
1515
  else {
1482
- switch (typeof objItem) {
1516
+ switch (typeof obj) {
1483
1517
  case "object":
1484
- if (typeof objItem[Symbol.iterator] === "function") {
1485
- /* 可迭代 */
1486
- itemResult = objItem.length === 0;
1518
+ if (typeof obj[Symbol.iterator] === "function") {
1519
+ // 可迭代
1520
+ // Map Array NodeList HTMLCollection
1521
+ if (obj instanceof Map) {
1522
+ flag = obj.size === 0;
1523
+ }
1524
+ else {
1525
+ const length = obj.length;
1526
+ if (typeof length === "number") {
1527
+ flag = length === 0;
1528
+ }
1529
+ }
1487
1530
  }
1488
1531
  else {
1489
- itemResult = Object.keys(objItem).length === 0;
1532
+ if (obj?.toString() === "[object Object]") {
1533
+ // {}
1534
+ flag = Object.keys(obj).length === 0;
1535
+ }
1490
1536
  }
1491
1537
  break;
1492
1538
  case "number":
1493
- itemResult = objItem === 0;
1539
+ flag = isNaN(obj) ? true : obj === 0;
1494
1540
  break;
1495
- case "string":
1496
- itemResult = objItem.trim() === "" || objItem === "null" || objItem === "undefined";
1541
+ case "string": {
1542
+ const trimStr = obj.trim();
1543
+ flag = trimStr.trim() === "" || trimStr === "null" || trimStr === "undefined";
1497
1544
  break;
1545
+ }
1498
1546
  case "boolean":
1499
- itemResult = !objItem;
1547
+ flag = !obj;
1500
1548
  break;
1501
1549
  case "function": {
1502
- const funcStr = objItem.toString().replace(/\s/g, "");
1550
+ const funcStr = obj.toString().replace(/\s/g, "");
1503
1551
  /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
1504
- itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
1552
+ flag = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
1505
1553
  break;
1506
1554
  }
1507
1555
  }
1508
1556
  }
1509
- result = result && itemResult;
1557
+ result = result && flag;
1510
1558
  }
1511
1559
  return result;
1512
1560
  }
@@ -1640,6 +1688,12 @@ define((function () { 'use strict';
1640
1688
  this.set(key, value);
1641
1689
  }
1642
1690
  }
1691
+ [Symbol.dispose]() {
1692
+ this.clear();
1693
+ }
1694
+ async [Symbol.asyncDispose]() {
1695
+ this.clear();
1696
+ }
1643
1697
  /**
1644
1698
  * 获取字典的长度,同this.size
1645
1699
  */
@@ -2151,11 +2205,11 @@ define((function () { 'use strict';
2151
2205
  return "";
2152
2206
  }
2153
2207
  try {
2154
- new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2155
- let args = Array.prototype.slice.call(arguments, 0);
2156
- let obj = this;
2157
- hookFunc.apply(obj, args);
2158
- return _context['realFunc_${_funcName}'].apply(obj, args);
2208
+ new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2209
+ let args = Array.prototype.slice.call(arguments, 0);
2210
+ let obj = this;
2211
+ hookFunc.apply(obj, args);
2212
+ return _context['realFunc_${_funcName}'].apply(obj, args);
2159
2213
  };`)(_context, _funcName, hookFunc);
2160
2214
  _context[_funcName].prototype.isHooked = true;
2161
2215
  return true;
@@ -4175,11 +4229,11 @@ define((function () { 'use strict';
4175
4229
  this.constructors = [];
4176
4230
  let options = {
4177
4231
  target: window,
4178
- entrypoint: 'webpackJsonp',
4232
+ entrypoint: "webpackJsonp",
4179
4233
  debug: false,
4180
4234
  strict: false,
4181
4235
  };
4182
- if (typeof opts === 'object') {
4236
+ if (typeof opts === "object") {
4183
4237
  options = Object.assign(Object.assign({}, options), opts);
4184
4238
  }
4185
4239
  this.target = options.target;
@@ -4218,7 +4272,7 @@ define((function () { 'use strict';
4218
4272
  * @internal
4219
4273
  */
4220
4274
  fillModules() {
4221
- if (typeof this.target[this.entrypoint] === 'function') {
4275
+ if (typeof this.target[this.entrypoint] === "function") {
4222
4276
  this.functionArguments.forEach((argument, index) => {
4223
4277
  try {
4224
4278
  if (this.modules && Object.keys(this.modules).length > 0)
@@ -4245,8 +4299,9 @@ define((function () { 'use strict';
4245
4299
  if (this.modules && Object.keys(this.modules).length == 0) {
4246
4300
  let moduleEnd = false;
4247
4301
  let moduleIterator = 0;
4248
- if (typeof this.target[this.entrypoint] != 'function' || !this.target[this.entrypoint]([], [], [moduleIterator])) {
4249
- throw Error('Unknown Webpack structure');
4302
+ if (typeof this.target[this.entrypoint] != "function" ||
4303
+ !this.target[this.entrypoint]([], [], [moduleIterator])) {
4304
+ throw Error("Unknown Webpack structure");
4250
4305
  }
4251
4306
  while (!moduleEnd) {
4252
4307
  try {
@@ -4279,7 +4334,7 @@ define((function () { 'use strict';
4279
4334
  const originalPush = this.target[this.entrypoint].push;
4280
4335
  this.target[this.entrypoint].push = (...args) => {
4281
4336
  const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
4282
- document.dispatchEvent(new CustomEvent('moduleraid:webpack-push', { detail: args }));
4337
+ document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
4283
4338
  return result;
4284
4339
  };
4285
4340
  }
@@ -4302,13 +4357,15 @@ define((function () { 'use strict';
4302
4357
  }
4303
4358
  let windowObjects = Object.keys(this.target);
4304
4359
  windowObjects = windowObjects
4305
- .filter((object) => object.toLowerCase().includes('chunk') || object.toLowerCase().includes('webpack'))
4306
- .filter((object) => typeof this.target[object] === 'function' || Array.isArray(this.target[object]));
4360
+ .filter((object) => object.toLowerCase().includes("chunk") ||
4361
+ object.toLowerCase().includes("webpack"))
4362
+ .filter((object) => typeof this.target[object] === "function" ||
4363
+ Array.isArray(this.target[object]));
4307
4364
  if (windowObjects.length > 1) {
4308
- throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(', ')}`);
4365
+ throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(", ")}`);
4309
4366
  }
4310
4367
  if (windowObjects.length === 0) {
4311
- throw Error('No Webpack JSONP entrypoints could be detected');
4368
+ throw Error("No Webpack JSONP entrypoints could be detected");
4312
4369
  }
4313
4370
  this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
4314
4371
  this.entrypoint = windowObjects[0];
@@ -4325,11 +4382,11 @@ define((function () { 'use strict';
4325
4382
  for (const key in object) {
4326
4383
  const value = object[key];
4327
4384
  const lowerCaseQuery = query.toLowerCase();
4328
- if (typeof value != 'object') {
4385
+ if (typeof value != "object") {
4329
4386
  const lowerCaseKey = key.toString().toLowerCase();
4330
4387
  if (lowerCaseKey.includes(lowerCaseQuery))
4331
4388
  return true;
4332
- if (typeof value != 'object') {
4389
+ if (typeof value != "object") {
4333
4390
  const lowerCaseValue = value.toString().toLowerCase();
4334
4391
  if (lowerCaseValue.includes(lowerCaseQuery))
4335
4392
  return true;
@@ -4369,31 +4426,31 @@ define((function () { 'use strict';
4369
4426
  const results = [];
4370
4427
  const modules = Object.keys(this.modules);
4371
4428
  if (modules.length === 0) {
4372
- throw new Error('There are no modules to search through!');
4429
+ throw new Error("There are no modules to search through!");
4373
4430
  }
4374
4431
  modules.forEach((key) => {
4375
4432
  const module = this.modules[key.toString()];
4376
4433
  if (module === undefined)
4377
4434
  return;
4378
4435
  try {
4379
- if (typeof query === 'string') {
4436
+ if (typeof query === "string") {
4380
4437
  query = query.toLowerCase();
4381
4438
  switch (typeof module) {
4382
- case 'string':
4439
+ case "string":
4383
4440
  if (module.toLowerCase().includes(query))
4384
4441
  results.push(module);
4385
4442
  break;
4386
- case 'function':
4443
+ case "function":
4387
4444
  if (module.toString().toLowerCase().includes(query))
4388
4445
  results.push(module);
4389
4446
  break;
4390
- case 'object':
4447
+ case "object":
4391
4448
  if (this.searchObject(module, query))
4392
4449
  results.push(module);
4393
4450
  break;
4394
4451
  }
4395
4452
  }
4396
- else if (typeof query === 'function') {
4453
+ else if (typeof query === "function") {
4397
4454
  if (query(module))
4398
4455
  results.push(module);
4399
4456
  }
@@ -4446,17 +4503,17 @@ define((function () { 'use strict';
4446
4503
  const results = [];
4447
4504
  const constructors = Object.keys(this.constructors);
4448
4505
  if (constructors.length === 0) {
4449
- throw new Error('There are no constructors to search through!');
4506
+ throw new Error("There are no constructors to search through!");
4450
4507
  }
4451
4508
  constructors.forEach((key) => {
4452
4509
  const constructor = this.constructors[key];
4453
4510
  try {
4454
- if (typeof query === 'string') {
4511
+ if (typeof query === "string") {
4455
4512
  query = query.toLowerCase();
4456
4513
  if (constructor.toString().toLowerCase().includes(query))
4457
4514
  results.push([this.constructors[key], this.modules[key]]);
4458
4515
  }
4459
- else if (typeof query === 'function') {
4516
+ else if (typeof query === "function") {
4460
4517
  if (query(constructor))
4461
4518
  results.push([this.constructors[key], this.modules[key]]);
4462
4519
  }
@@ -5748,7 +5805,7 @@ define((function () { 'use strict';
5748
5805
  }
5749
5806
  return strFound ? true : false;
5750
5807
  }
5751
- formatByteToSize(byteSize, addType = true) {
5808
+ formatByteToSize(byteSize, addType = true, unit = "1024") {
5752
5809
  byteSize = parseInt(byteSize.toString());
5753
5810
  if (isNaN(byteSize)) {
5754
5811
  throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
@@ -5756,8 +5813,9 @@ define((function () { 'use strict';
5756
5813
  let result = 0;
5757
5814
  let resultType = "KB";
5758
5815
  const sizeData = {};
5816
+ const unitNumber = Number(unit);
5759
5817
  sizeData.B = 1;
5760
- sizeData.KB = 1024;
5818
+ sizeData.KB = unitNumber;
5761
5819
  sizeData.MB = sizeData.KB * sizeData.KB;
5762
5820
  sizeData.GB = sizeData.MB * sizeData.KB;
5763
5821
  sizeData.TB = sizeData.GB * sizeData.KB;