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