@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.amd.js +38 -16
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +38 -16
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +38 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +38 -16
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +38 -16
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +38 -16
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +15 -1
- package/dist/src/Utils.d.ts +1 -1
- package/dist/src/UtilsCommon.d.ts +4 -0
- package/package.json +1 -1
- package/src/Httpx.ts +40 -9
- package/src/Utils.ts +2 -15
- package/src/UtilsCommon.ts +20 -0
package/dist/index.iife.js
CHANGED
|
@@ -1533,12 +1533,21 @@ var Utils = (function () {
|
|
|
1533
1533
|
}
|
|
1534
1534
|
}
|
|
1535
1535
|
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1536
|
+
/**
|
|
1537
|
+
* 生成uuid
|
|
1538
|
+
*/
|
|
1539
|
+
const GenerateUUID = function () {
|
|
1540
|
+
if (typeof UtilsCore.globalThis?.crypto?.randomUUID === "function") {
|
|
1541
|
+
return UtilsCore.globalThis.crypto.randomUUID();
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
1545
|
+
var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
1546
|
+
return randomCharValue.toString(16);
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1541
1549
|
};
|
|
1550
|
+
|
|
1542
1551
|
class Httpx {
|
|
1543
1552
|
GM_Api = {
|
|
1544
1553
|
xmlHttpRequest: null,
|
|
@@ -1557,6 +1566,12 @@ var Utils = (function () {
|
|
|
1557
1566
|
* @private
|
|
1558
1567
|
*/
|
|
1559
1568
|
beforeRequestCallBack(details) {
|
|
1569
|
+
if (!details.allowInterceptConfig) {
|
|
1570
|
+
return details;
|
|
1571
|
+
}
|
|
1572
|
+
if (!details.allowInterceptConfig.beforeRequest) {
|
|
1573
|
+
return details;
|
|
1574
|
+
}
|
|
1560
1575
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1561
1576
|
let item = this.$config.configList[index];
|
|
1562
1577
|
if (typeof item.fn === "function") {
|
|
@@ -1618,6 +1633,12 @@ var Utils = (function () {
|
|
|
1618
1633
|
* @param details 请求的配置
|
|
1619
1634
|
*/
|
|
1620
1635
|
successResponseCallBack(response, details) {
|
|
1636
|
+
if (!details.allowInterceptConfig) {
|
|
1637
|
+
return details;
|
|
1638
|
+
}
|
|
1639
|
+
if (!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1640
|
+
return details;
|
|
1641
|
+
}
|
|
1621
1642
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1622
1643
|
let item = this.$config.configList[index];
|
|
1623
1644
|
if (typeof item.successFn === "function") {
|
|
@@ -1633,6 +1654,12 @@ var Utils = (function () {
|
|
|
1633
1654
|
* @param data 配置
|
|
1634
1655
|
*/
|
|
1635
1656
|
errorResponseCallBack(data) {
|
|
1657
|
+
if (!data.details.allowInterceptConfig) {
|
|
1658
|
+
return data;
|
|
1659
|
+
}
|
|
1660
|
+
if (!data.details.allowInterceptConfig.afterResponseError) {
|
|
1661
|
+
return data;
|
|
1662
|
+
}
|
|
1636
1663
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1637
1664
|
let item = this.$config.configList[index];
|
|
1638
1665
|
if (typeof item.errorFn === "function") {
|
|
@@ -2244,6 +2271,11 @@ var Utils = (function () {
|
|
|
2244
2271
|
anonymous: void 0,
|
|
2245
2272
|
fetch: void 0,
|
|
2246
2273
|
fetchInit: void 0,
|
|
2274
|
+
allowInterceptConfig: {
|
|
2275
|
+
beforeRequest: true,
|
|
2276
|
+
afterResponseSuccess: true,
|
|
2277
|
+
afterResponseError: true,
|
|
2278
|
+
},
|
|
2247
2279
|
user: void 0,
|
|
2248
2280
|
password: void 0,
|
|
2249
2281
|
onabort() { },
|
|
@@ -6357,17 +6389,7 @@ var Utils = (function () {
|
|
|
6357
6389
|
* @example
|
|
6358
6390
|
* Utils.generateUUID()
|
|
6359
6391
|
*/
|
|
6360
|
-
generateUUID
|
|
6361
|
-
if (typeof globalThis?.crypto?.randomUUID === "function") {
|
|
6362
|
-
return globalThis.crypto.randomUUID();
|
|
6363
|
-
}
|
|
6364
|
-
else {
|
|
6365
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
6366
|
-
var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
6367
|
-
return randomCharValue.toString(16);
|
|
6368
|
-
});
|
|
6369
|
-
}
|
|
6370
|
-
}
|
|
6392
|
+
generateUUID = GenerateUUID;
|
|
6371
6393
|
}
|
|
6372
6394
|
let utils = new Utils();
|
|
6373
6395
|
|