@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.umd.js CHANGED
@@ -61,47 +61,7 @@
61
61
  const cache = createCache(LAST_NUMBER_WEAK_MAP);
62
62
  const generateUniqueNumber = createGenerateUniqueNumber(cache, LAST_NUMBER_WEAK_MAP);
63
63
 
64
- const isMessagePort = (sender) => {
65
- return typeof sender.start === 'function';
66
- };
67
-
68
- const PORT_MAP = new WeakMap();
69
-
70
- const extendBrokerImplementation = (partialBrokerImplementation) => ({
71
- ...partialBrokerImplementation,
72
- connect: ({ call }) => {
73
- return async () => {
74
- const { port1, port2 } = new MessageChannel();
75
- const portId = await call('connect', { port: port1 }, [port1]);
76
- PORT_MAP.set(port2, portId);
77
- return port2;
78
- };
79
- },
80
- disconnect: ({ call }) => {
81
- return async (port) => {
82
- const portId = PORT_MAP.get(port);
83
- if (portId === undefined) {
84
- throw new Error('The given port is not connected.');
85
- }
86
- await call('disconnect', { portId });
87
- };
88
- },
89
- isSupported: ({ call }) => {
90
- return () => call('isSupported');
91
- }
92
- });
93
-
94
- const ONGOING_REQUESTS = new WeakMap();
95
- const createOrGetOngoingRequests = (sender) => {
96
- if (ONGOING_REQUESTS.has(sender)) {
97
- // @todo TypeScript needs to be convinced that has() works as expected.
98
- return ONGOING_REQUESTS.get(sender);
99
- }
100
- const ongoingRequests = new Map();
101
- ONGOING_REQUESTS.set(sender, ongoingRequests);
102
- return ongoingRequests;
103
- };
104
- const createBroker = (brokerImplementation) => {
64
+ const createBrokerFactory = (createOrGetOngoingRequests, extendBrokerImplementation, generateUniqueNumber, isMessagePort) => (brokerImplementation) => {
105
65
  const fullBrokerImplementation = extendBrokerImplementation(brokerImplementation);
106
66
  return (sender) => {
107
67
  const ongoingRequests = createOrGetOngoingRequests(sender);
@@ -144,6 +104,46 @@
144
104
  };
145
105
  };
146
106
 
107
+ const createCreateOrGetOngoingRequests = (ongoingRequestsMap) => (sender) => {
108
+ if (ongoingRequestsMap.has(sender)) {
109
+ // @todo TypeScript needs to be convinced that has() works as expected.
110
+ return ongoingRequestsMap.get(sender);
111
+ }
112
+ const ongoingRequests = new Map();
113
+ ongoingRequestsMap.set(sender, ongoingRequests);
114
+ return ongoingRequests;
115
+ };
116
+
117
+ const createExtendBrokerImplementation = (portMap) => (partialBrokerImplementation) => ({
118
+ ...partialBrokerImplementation,
119
+ connect: ({ call }) => {
120
+ return async () => {
121
+ const { port1, port2 } = new MessageChannel();
122
+ const portId = await call('connect', { port: port1 }, [port1]);
123
+ portMap.set(port2, portId);
124
+ return port2;
125
+ };
126
+ },
127
+ disconnect: ({ call }) => {
128
+ return async (port) => {
129
+ const portId = portMap.get(port);
130
+ if (portId === undefined) {
131
+ throw new Error('The given port is not connected.');
132
+ }
133
+ await call('disconnect', { portId });
134
+ };
135
+ },
136
+ isSupported: ({ call }) => {
137
+ return () => call('isSupported');
138
+ }
139
+ });
140
+
141
+ const isMessagePort = (sender) => {
142
+ return typeof sender.start === 'function';
143
+ };
144
+
145
+ const createBroker = createBrokerFactory(createCreateOrGetOngoingRequests(new WeakMap()), createExtendBrokerImplementation(new WeakMap()), generateUniqueNumber, isMessagePort);
146
+
147
147
  const createClearIntervalFactory = (scheduledIntervalsState) => (clear) => (timerId) => {
148
148
  if (typeof scheduledIntervalsState.get(timerId) === 'symbol') {
149
149
  scheduledIntervalsState.set(timerId, null);
@@ -235,7 +235,7 @@
235
235
  };
236
236
 
237
237
  // This is the minified and stringified code of the worker-timers-worker package.
238
- 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
238
+ 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
239
239
 
240
240
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
241
241
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
@@ -243,7 +243,7 @@
243
243
  const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
244
244
  const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
245
245
 
246
- const version = "2.9.11";
246
+ const version = "2.9.13";
247
247
 
248
248
  /* eslint-disable */
249
249
  // ==UserScript==
@@ -283,7 +283,9 @@
283
283
  const emptyFn = () => { };
284
284
  const errorFn = (e) => console.error(e);
285
285
  function isThenable(obj) {
286
- return obj && ["object", "function"].includes(typeof obj) && typeof obj.then === "function";
286
+ return (obj &&
287
+ ["object", "function"].includes(typeof obj) &&
288
+ typeof obj.then === "function");
287
289
  }
288
290
  function catchError(fn, ...args) {
289
291
  try {
@@ -324,7 +326,8 @@
324
326
  if (!value)
325
327
  continue;
326
328
  const lheader = header.toLowerCase();
327
- headers[lheader] = lheader in headers ? `${headers[lheader]}, ${value}` : value;
329
+ headers[lheader] =
330
+ lheader in headers ? `${headers[lheader]}, ${value}` : value;
328
331
  }
329
332
  break;
330
333
  case "[object Headers]":
@@ -363,9 +366,11 @@
363
366
  !filters.find((obj) => {
364
367
  switch (true) {
365
368
  case obj.type && obj.type !== type:
366
- case getType(obj.url) === "[object String]" && !url.includes(obj.url):
369
+ case getType(obj.url) === "[object String]" &&
370
+ !url.includes(obj.url):
367
371
  case getType(obj.url) === "[object RegExp]" && !obj.url.test(url):
368
- case obj.method && obj.method.toUpperCase() !== method.toUpperCase():
372
+ case obj.method &&
373
+ obj.method.toUpperCase() !== method.toUpperCase():
369
374
  case "async" in obj && obj.async !== async:
370
375
  return false;
371
376
  }
@@ -408,7 +413,8 @@
408
413
  if (getType(this.request.response) === "[object Function]") {
409
414
  catchError(this.request.response, response);
410
415
  responseKeys.forEach((key) => {
411
- if ("get" in getDescriptor(response, key) || isThenable(response[key])) {
416
+ if ("get" in getDescriptor(response, key) ||
417
+ isThenable(response[key])) {
412
418
  delete response[key];
413
419
  }
414
420
  });
@@ -429,7 +435,10 @@
429
435
  const proxyHandler = {
430
436
  get(target, prop) {
431
437
  const descriptor = getDescriptor(target, prop);
432
- if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.get)
438
+ if (descriptor &&
439
+ !descriptor.configurable &&
440
+ !descriptor.writable &&
441
+ !descriptor.get)
433
442
  return target[prop];
434
443
  const ah = target.__ajaxHooker;
435
444
  if (ah && ah.proxyProps) {
@@ -448,7 +457,10 @@
448
457
  },
449
458
  set(target, prop, value) {
450
459
  const descriptor = getDescriptor(target, prop);
451
- if (descriptor && !descriptor.configurable && !descriptor.writable && !descriptor.set)
460
+ if (descriptor &&
461
+ !descriptor.configurable &&
462
+ !descriptor.writable &&
463
+ !descriptor.set)
452
464
  return true;
453
465
  const ah = target.__ajaxHooker;
454
466
  if (ah && ah.proxyProps && prop in ah.proxyProps) {
@@ -472,7 +484,9 @@
472
484
  proxyEvents: {},
473
485
  });
474
486
  xhr.addEventListener("readystatechange", (e) => {
475
- if (ah.proxyXhr.readyState === 4 && ah.request && typeof ah.request.response === "function") {
487
+ if (ah.proxyXhr.readyState === 4 &&
488
+ ah.request &&
489
+ typeof ah.request.response === "function") {
476
490
  const response = {
477
491
  finalUrl: ah.proxyXhr.responseURL,
478
492
  status: ah.proxyXhr.status,
@@ -491,7 +505,9 @@
491
505
  response[key] = val;
492
506
  });
493
507
  }
494
- ah.resThenable = new AHRequest(ah.request).waitForResponseKeys(response).then(() => {
508
+ ah.resThenable = new AHRequest(ah.request)
509
+ .waitForResponseKeys(response)
510
+ .then(() => {
495
511
  for (const key of xhrResponses) {
496
512
  ah.proxyProps[key] = {
497
513
  get: () => {
@@ -514,7 +530,13 @@
514
530
  set: (val) => ah.addEvent(onEvt, val),
515
531
  };
516
532
  }
517
- for (const method of ["setRequestHeader", "addEventListener", "removeEventListener", "open", "send"]) {
533
+ for (const method of [
534
+ "setRequestHeader",
535
+ "addEventListener",
536
+ "removeEventListener",
537
+ "open",
538
+ "send",
539
+ ]) {
518
540
  ah.proxyProps[method] = { value: ah[method] };
519
541
  }
520
542
  }
@@ -561,7 +583,8 @@
561
583
  if (!this.request)
562
584
  return;
563
585
  const headers = this.request.headers;
564
- headers[header] = header in headers ? `${headers[header]}, ${value}` : value;
586
+ headers[header] =
587
+ header in headers ? `${headers[header]}, ${value}` : value;
565
588
  }
566
589
  addEventListener(...args) {
567
590
  if (xhrAsyncEvents.includes(args[0])) {
@@ -592,7 +615,13 @@
592
615
  };
593
616
  this.openArgs = args;
594
617
  this.resThenable = new SyncThenable();
595
- ["responseURL", "readyState", "status", "statusText", ...xhrResponses].forEach((key) => {
618
+ [
619
+ "responseURL",
620
+ "readyState",
621
+ "status",
622
+ "statusText",
623
+ ...xhrResponses,
624
+ ].forEach((key) => {
596
625
  delete this.proxyProps[key];
597
626
  });
598
627
  return this.originalXhr.open(method, url, async, ...args);
@@ -754,13 +783,17 @@
754
783
  // 针对头条、抖音 secsdk.umd.js 的兼容性处理
755
784
  class AHFunction extends Function {
756
785
  call(thisArg, ...args) {
757
- if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
786
+ if (thisArg &&
787
+ thisArg.__ajaxHooker &&
788
+ thisArg.__ajaxHooker.proxyXhr === thisArg) {
758
789
  thisArg = thisArg.__ajaxHooker.originalXhr;
759
790
  }
760
791
  return Reflect.apply(this, thisArg, args);
761
792
  }
762
793
  apply(thisArg, args) {
763
- if (thisArg && thisArg.__ajaxHooker && thisArg.__ajaxHooker.proxyXhr === thisArg) {
794
+ if (thisArg &&
795
+ thisArg.__ajaxHooker &&
796
+ thisArg.__ajaxHooker.proxyXhr === thisArg) {
764
797
  thisArg = thisArg.__ajaxHooker.originalXhr;
765
798
  }
766
799
  return Reflect.apply(this, thisArg, args || []);
@@ -1477,40 +1510,55 @@
1477
1510
  isNull(...args) {
1478
1511
  let result = true;
1479
1512
  const checkList = [...args];
1480
- for (const objItem of checkList) {
1481
- let itemResult = false;
1482
- if (objItem === null || objItem === undefined) {
1483
- itemResult = true;
1513
+ for (const obj of checkList) {
1514
+ let flag = false;
1515
+ if (obj === null || obj === undefined) {
1516
+ // null undefined
1517
+ flag = true;
1484
1518
  }
1485
1519
  else {
1486
- switch (typeof objItem) {
1520
+ switch (typeof obj) {
1487
1521
  case "object":
1488
- if (typeof objItem[Symbol.iterator] === "function") {
1489
- /* 可迭代 */
1490
- itemResult = objItem.length === 0;
1522
+ if (typeof obj[Symbol.iterator] === "function") {
1523
+ // 可迭代
1524
+ // Map Array NodeList HTMLCollection
1525
+ if (obj instanceof Map) {
1526
+ flag = obj.size === 0;
1527
+ }
1528
+ else {
1529
+ const length = obj.length;
1530
+ if (typeof length === "number") {
1531
+ flag = length === 0;
1532
+ }
1533
+ }
1491
1534
  }
1492
1535
  else {
1493
- itemResult = Object.keys(objItem).length === 0;
1536
+ if (obj?.toString() === "[object Object]") {
1537
+ // {}
1538
+ flag = Object.keys(obj).length === 0;
1539
+ }
1494
1540
  }
1495
1541
  break;
1496
1542
  case "number":
1497
- itemResult = objItem === 0;
1543
+ flag = isNaN(obj) ? true : obj === 0;
1498
1544
  break;
1499
- case "string":
1500
- itemResult = objItem.trim() === "" || objItem === "null" || objItem === "undefined";
1545
+ case "string": {
1546
+ const trimStr = obj.trim();
1547
+ flag = trimStr.trim() === "" || trimStr === "null" || trimStr === "undefined";
1501
1548
  break;
1549
+ }
1502
1550
  case "boolean":
1503
- itemResult = !objItem;
1551
+ flag = !obj;
1504
1552
  break;
1505
1553
  case "function": {
1506
- const funcStr = objItem.toString().replace(/\s/g, "");
1554
+ const funcStr = obj.toString().replace(/\s/g, "");
1507
1555
  /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
1508
- itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
1556
+ flag = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
1509
1557
  break;
1510
1558
  }
1511
1559
  }
1512
1560
  }
1513
- result = result && itemResult;
1561
+ result = result && flag;
1514
1562
  }
1515
1563
  return result;
1516
1564
  }
@@ -1644,6 +1692,12 @@
1644
1692
  this.set(key, value);
1645
1693
  }
1646
1694
  }
1695
+ [Symbol.dispose]() {
1696
+ this.clear();
1697
+ }
1698
+ async [Symbol.asyncDispose]() {
1699
+ this.clear();
1700
+ }
1647
1701
  /**
1648
1702
  * 获取字典的长度,同this.size
1649
1703
  */
@@ -2155,11 +2209,11 @@
2155
2209
  return "";
2156
2210
  }
2157
2211
  try {
2158
- new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2159
- let args = Array.prototype.slice.call(arguments, 0);
2160
- let obj = this;
2161
- hookFunc.apply(obj, args);
2162
- return _context['realFunc_${_funcName}'].apply(obj, args);
2212
+ new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2213
+ let args = Array.prototype.slice.call(arguments, 0);
2214
+ let obj = this;
2215
+ hookFunc.apply(obj, args);
2216
+ return _context['realFunc_${_funcName}'].apply(obj, args);
2163
2217
  };`)(_context, _funcName, hookFunc);
2164
2218
  _context[_funcName].prototype.isHooked = true;
2165
2219
  return true;
@@ -4179,11 +4233,11 @@
4179
4233
  this.constructors = [];
4180
4234
  let options = {
4181
4235
  target: window,
4182
- entrypoint: 'webpackJsonp',
4236
+ entrypoint: "webpackJsonp",
4183
4237
  debug: false,
4184
4238
  strict: false,
4185
4239
  };
4186
- if (typeof opts === 'object') {
4240
+ if (typeof opts === "object") {
4187
4241
  options = Object.assign(Object.assign({}, options), opts);
4188
4242
  }
4189
4243
  this.target = options.target;
@@ -4222,7 +4276,7 @@
4222
4276
  * @internal
4223
4277
  */
4224
4278
  fillModules() {
4225
- if (typeof this.target[this.entrypoint] === 'function') {
4279
+ if (typeof this.target[this.entrypoint] === "function") {
4226
4280
  this.functionArguments.forEach((argument, index) => {
4227
4281
  try {
4228
4282
  if (this.modules && Object.keys(this.modules).length > 0)
@@ -4249,8 +4303,9 @@
4249
4303
  if (this.modules && Object.keys(this.modules).length == 0) {
4250
4304
  let moduleEnd = false;
4251
4305
  let moduleIterator = 0;
4252
- if (typeof this.target[this.entrypoint] != 'function' || !this.target[this.entrypoint]([], [], [moduleIterator])) {
4253
- throw Error('Unknown Webpack structure');
4306
+ if (typeof this.target[this.entrypoint] != "function" ||
4307
+ !this.target[this.entrypoint]([], [], [moduleIterator])) {
4308
+ throw Error("Unknown Webpack structure");
4254
4309
  }
4255
4310
  while (!moduleEnd) {
4256
4311
  try {
@@ -4283,7 +4338,7 @@
4283
4338
  const originalPush = this.target[this.entrypoint].push;
4284
4339
  this.target[this.entrypoint].push = (...args) => {
4285
4340
  const result = Reflect.apply(originalPush, this.target[this.entrypoint], args);
4286
- document.dispatchEvent(new CustomEvent('moduleraid:webpack-push', { detail: args }));
4341
+ document.dispatchEvent(new CustomEvent("moduleraid:webpack-push", { detail: args }));
4287
4342
  return result;
4288
4343
  };
4289
4344
  }
@@ -4306,13 +4361,15 @@
4306
4361
  }
4307
4362
  let windowObjects = Object.keys(this.target);
4308
4363
  windowObjects = windowObjects
4309
- .filter((object) => object.toLowerCase().includes('chunk') || object.toLowerCase().includes('webpack'))
4310
- .filter((object) => typeof this.target[object] === 'function' || Array.isArray(this.target[object]));
4364
+ .filter((object) => object.toLowerCase().includes("chunk") ||
4365
+ object.toLowerCase().includes("webpack"))
4366
+ .filter((object) => typeof this.target[object] === "function" ||
4367
+ Array.isArray(this.target[object]));
4311
4368
  if (windowObjects.length > 1) {
4312
- throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(', ')}`);
4369
+ throw Error(`Multiple possible endpoints have been detected, please create a new moduleRaid instance with a specific one:\n${windowObjects.join(", ")}`);
4313
4370
  }
4314
4371
  if (windowObjects.length === 0) {
4315
- throw Error('No Webpack JSONP entrypoints could be detected');
4372
+ throw Error("No Webpack JSONP entrypoints could be detected");
4316
4373
  }
4317
4374
  this.log(`Entrypoint has been detected at window.${windowObjects[0]} and set for injection`);
4318
4375
  this.entrypoint = windowObjects[0];
@@ -4329,11 +4386,11 @@
4329
4386
  for (const key in object) {
4330
4387
  const value = object[key];
4331
4388
  const lowerCaseQuery = query.toLowerCase();
4332
- if (typeof value != 'object') {
4389
+ if (typeof value != "object") {
4333
4390
  const lowerCaseKey = key.toString().toLowerCase();
4334
4391
  if (lowerCaseKey.includes(lowerCaseQuery))
4335
4392
  return true;
4336
- if (typeof value != 'object') {
4393
+ if (typeof value != "object") {
4337
4394
  const lowerCaseValue = value.toString().toLowerCase();
4338
4395
  if (lowerCaseValue.includes(lowerCaseQuery))
4339
4396
  return true;
@@ -4373,31 +4430,31 @@
4373
4430
  const results = [];
4374
4431
  const modules = Object.keys(this.modules);
4375
4432
  if (modules.length === 0) {
4376
- throw new Error('There are no modules to search through!');
4433
+ throw new Error("There are no modules to search through!");
4377
4434
  }
4378
4435
  modules.forEach((key) => {
4379
4436
  const module = this.modules[key.toString()];
4380
4437
  if (module === undefined)
4381
4438
  return;
4382
4439
  try {
4383
- if (typeof query === 'string') {
4440
+ if (typeof query === "string") {
4384
4441
  query = query.toLowerCase();
4385
4442
  switch (typeof module) {
4386
- case 'string':
4443
+ case "string":
4387
4444
  if (module.toLowerCase().includes(query))
4388
4445
  results.push(module);
4389
4446
  break;
4390
- case 'function':
4447
+ case "function":
4391
4448
  if (module.toString().toLowerCase().includes(query))
4392
4449
  results.push(module);
4393
4450
  break;
4394
- case 'object':
4451
+ case "object":
4395
4452
  if (this.searchObject(module, query))
4396
4453
  results.push(module);
4397
4454
  break;
4398
4455
  }
4399
4456
  }
4400
- else if (typeof query === 'function') {
4457
+ else if (typeof query === "function") {
4401
4458
  if (query(module))
4402
4459
  results.push(module);
4403
4460
  }
@@ -4450,17 +4507,17 @@
4450
4507
  const results = [];
4451
4508
  const constructors = Object.keys(this.constructors);
4452
4509
  if (constructors.length === 0) {
4453
- throw new Error('There are no constructors to search through!');
4510
+ throw new Error("There are no constructors to search through!");
4454
4511
  }
4455
4512
  constructors.forEach((key) => {
4456
4513
  const constructor = this.constructors[key];
4457
4514
  try {
4458
- if (typeof query === 'string') {
4515
+ if (typeof query === "string") {
4459
4516
  query = query.toLowerCase();
4460
4517
  if (constructor.toString().toLowerCase().includes(query))
4461
4518
  results.push([this.constructors[key], this.modules[key]]);
4462
4519
  }
4463
- else if (typeof query === 'function') {
4520
+ else if (typeof query === "function") {
4464
4521
  if (query(constructor))
4465
4522
  results.push([this.constructors[key], this.modules[key]]);
4466
4523
  }
@@ -5752,7 +5809,7 @@
5752
5809
  }
5753
5810
  return strFound ? true : false;
5754
5811
  }
5755
- formatByteToSize(byteSize, addType = true) {
5812
+ formatByteToSize(byteSize, addType = true, unit = "1024") {
5756
5813
  byteSize = parseInt(byteSize.toString());
5757
5814
  if (isNaN(byteSize)) {
5758
5815
  throw new Error("Utils.formatByteToSize 参数 byteSize 格式不正确");
@@ -5760,8 +5817,9 @@
5760
5817
  let result = 0;
5761
5818
  let resultType = "KB";
5762
5819
  const sizeData = {};
5820
+ const unitNumber = Number(unit);
5763
5821
  sizeData.B = 1;
5764
- sizeData.KB = 1024;
5822
+ sizeData.KB = unitNumber;
5765
5823
  sizeData.MB = sizeData.KB * sizeData.KB;
5766
5824
  sizeData.GB = sizeData.MB * sizeData.KB;
5767
5825
  sizeData.TB = sizeData.GB * sizeData.KB;