@whitesev/utils 1.5.7 → 1.5.9

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() { },
@@ -6360,17 +6392,7 @@
6360
6392
  * @example
6361
6393
  * Utils.generateUUID()
6362
6394
  */
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
- }
6395
+ generateUUID = GenerateUUID;
6374
6396
  }
6375
6397
  let utils = new Utils();
6376
6398