@whitesev/utils 1.5.8 → 1.6.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.
@@ -1535,12 +1535,21 @@ System.register('Utils', [], (function (exports) {
1535
1535
  }
1536
1536
  }
1537
1537
 
1538
- const GenerateUUID = () => {
1539
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
1540
- var r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
1541
- return v.toString(16);
1542
- });
1538
+ /**
1539
+ * 生成uuid
1540
+ */
1541
+ const GenerateUUID = function () {
1542
+ if (typeof UtilsCore.globalThis?.crypto?.randomUUID === "function") {
1543
+ return UtilsCore.globalThis.crypto.randomUUID();
1544
+ }
1545
+ else {
1546
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
1547
+ var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
1548
+ return randomCharValue.toString(16);
1549
+ });
1550
+ }
1543
1551
  };
1552
+
1544
1553
  class Httpx {
1545
1554
  GM_Api = {
1546
1555
  xmlHttpRequest: null,
@@ -1559,6 +1568,12 @@ System.register('Utils', [], (function (exports) {
1559
1568
  * @private
1560
1569
  */
1561
1570
  beforeRequestCallBack(details) {
1571
+ if (!details.allowInterceptConfig) {
1572
+ return details;
1573
+ }
1574
+ if (!details.allowInterceptConfig.beforeRequest) {
1575
+ return details;
1576
+ }
1562
1577
  for (let index = 0; index < this.$config.configList.length; index++) {
1563
1578
  let item = this.$config.configList[index];
1564
1579
  if (typeof item.fn === "function") {
@@ -1620,6 +1635,12 @@ System.register('Utils', [], (function (exports) {
1620
1635
  * @param details 请求的配置
1621
1636
  */
1622
1637
  successResponseCallBack(response, details) {
1638
+ if (!details.allowInterceptConfig) {
1639
+ return details;
1640
+ }
1641
+ if (!details.allowInterceptConfig.afterResponseSuccess) {
1642
+ return details;
1643
+ }
1623
1644
  for (let index = 0; index < this.$config.configList.length; index++) {
1624
1645
  let item = this.$config.configList[index];
1625
1646
  if (typeof item.successFn === "function") {
@@ -1635,6 +1656,12 @@ System.register('Utils', [], (function (exports) {
1635
1656
  * @param data 配置
1636
1657
  */
1637
1658
  errorResponseCallBack(data) {
1659
+ if (!data.details.allowInterceptConfig) {
1660
+ return data;
1661
+ }
1662
+ if (!data.details.allowInterceptConfig.afterResponseError) {
1663
+ return data;
1664
+ }
1638
1665
  for (let index = 0; index < this.$config.configList.length; index++) {
1639
1666
  let item = this.$config.configList[index];
1640
1667
  if (typeof item.errorFn === "function") {
@@ -2246,6 +2273,11 @@ System.register('Utils', [], (function (exports) {
2246
2273
  anonymous: void 0,
2247
2274
  fetch: void 0,
2248
2275
  fetchInit: void 0,
2276
+ allowInterceptConfig: {
2277
+ beforeRequest: true,
2278
+ afterResponseSuccess: true,
2279
+ afterResponseError: true,
2280
+ },
2249
2281
  user: void 0,
2250
2282
  password: void 0,
2251
2283
  onabort() { },
@@ -3434,13 +3466,20 @@ System.register('Utils', [], (function (exports) {
3434
3466
  return source;
3435
3467
  }
3436
3468
  }
3469
+ if (source == null) {
3470
+ return target;
3471
+ }
3472
+ if (target == null) {
3473
+ target = {};
3474
+ }
3437
3475
  if (isAdd) {
3438
3476
  for (const sourceKeyName in source) {
3439
3477
  const targetKeyName = sourceKeyName;
3440
3478
  let targetValue = target[targetKeyName];
3441
3479
  let sourceValue = source[sourceKeyName];
3442
- if (sourceKeyName in target &&
3443
- typeof sourceValue === "object" &&
3480
+ if (typeof sourceValue === "object" &&
3481
+ sourceValue != null &&
3482
+ sourceKeyName in target &&
3444
3483
  !UtilsContext.isDOM(sourceValue)) {
3445
3484
  /* 源端的值是object类型,且不是元素节点 */
3446
3485
  target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
@@ -3455,6 +3494,7 @@ System.register('Utils', [], (function (exports) {
3455
3494
  let targetValue = target[targetKeyName];
3456
3495
  let sourceValue = source[targetKeyName];
3457
3496
  if (typeof sourceValue === "object" &&
3497
+ sourceValue != null &&
3458
3498
  !UtilsContext.isDOM(sourceValue) &&
3459
3499
  Object.keys(sourceValue).length) {
3460
3500
  /* 源端的值是object类型,且不是元素节点 */
@@ -6359,17 +6399,7 @@ System.register('Utils', [], (function (exports) {
6359
6399
  * @example
6360
6400
  * Utils.generateUUID()
6361
6401
  */
6362
- generateUUID() {
6363
- if (typeof globalThis?.crypto?.randomUUID === "function") {
6364
- return globalThis.crypto.randomUUID();
6365
- }
6366
- else {
6367
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
6368
- var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
6369
- return randomCharValue.toString(16);
6370
- });
6371
- }
6372
- }
6402
+ generateUUID = GenerateUUID;
6373
6403
  }
6374
6404
  let utils = exports("default", new Utils());
6375
6405