@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.esm.js
CHANGED
|
@@ -1530,12 +1530,21 @@ class Hooks {
|
|
|
1530
1530
|
}
|
|
1531
1531
|
}
|
|
1532
1532
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1533
|
+
/**
|
|
1534
|
+
* 生成uuid
|
|
1535
|
+
*/
|
|
1536
|
+
const GenerateUUID = function () {
|
|
1537
|
+
if (typeof UtilsCore.globalThis?.crypto?.randomUUID === "function") {
|
|
1538
|
+
return UtilsCore.globalThis.crypto.randomUUID();
|
|
1539
|
+
}
|
|
1540
|
+
else {
|
|
1541
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
1542
|
+
var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
1543
|
+
return randomCharValue.toString(16);
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1538
1546
|
};
|
|
1547
|
+
|
|
1539
1548
|
class Httpx {
|
|
1540
1549
|
GM_Api = {
|
|
1541
1550
|
xmlHttpRequest: null,
|
|
@@ -1554,6 +1563,12 @@ class Httpx {
|
|
|
1554
1563
|
* @private
|
|
1555
1564
|
*/
|
|
1556
1565
|
beforeRequestCallBack(details) {
|
|
1566
|
+
if (!details.allowInterceptConfig) {
|
|
1567
|
+
return details;
|
|
1568
|
+
}
|
|
1569
|
+
if (!details.allowInterceptConfig.beforeRequest) {
|
|
1570
|
+
return details;
|
|
1571
|
+
}
|
|
1557
1572
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1558
1573
|
let item = this.$config.configList[index];
|
|
1559
1574
|
if (typeof item.fn === "function") {
|
|
@@ -1615,6 +1630,12 @@ class Httpx {
|
|
|
1615
1630
|
* @param details 请求的配置
|
|
1616
1631
|
*/
|
|
1617
1632
|
successResponseCallBack(response, details) {
|
|
1633
|
+
if (!details.allowInterceptConfig) {
|
|
1634
|
+
return details;
|
|
1635
|
+
}
|
|
1636
|
+
if (!details.allowInterceptConfig.afterResponseSuccess) {
|
|
1637
|
+
return details;
|
|
1638
|
+
}
|
|
1618
1639
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1619
1640
|
let item = this.$config.configList[index];
|
|
1620
1641
|
if (typeof item.successFn === "function") {
|
|
@@ -1630,6 +1651,12 @@ class Httpx {
|
|
|
1630
1651
|
* @param data 配置
|
|
1631
1652
|
*/
|
|
1632
1653
|
errorResponseCallBack(data) {
|
|
1654
|
+
if (!data.details.allowInterceptConfig) {
|
|
1655
|
+
return data;
|
|
1656
|
+
}
|
|
1657
|
+
if (!data.details.allowInterceptConfig.afterResponseError) {
|
|
1658
|
+
return data;
|
|
1659
|
+
}
|
|
1633
1660
|
for (let index = 0; index < this.$config.configList.length; index++) {
|
|
1634
1661
|
let item = this.$config.configList[index];
|
|
1635
1662
|
if (typeof item.errorFn === "function") {
|
|
@@ -2241,6 +2268,11 @@ class Httpx {
|
|
|
2241
2268
|
anonymous: void 0,
|
|
2242
2269
|
fetch: void 0,
|
|
2243
2270
|
fetchInit: void 0,
|
|
2271
|
+
allowInterceptConfig: {
|
|
2272
|
+
beforeRequest: true,
|
|
2273
|
+
afterResponseSuccess: true,
|
|
2274
|
+
afterResponseError: true,
|
|
2275
|
+
},
|
|
2244
2276
|
user: void 0,
|
|
2245
2277
|
password: void 0,
|
|
2246
2278
|
onabort() { },
|
|
@@ -6354,17 +6386,7 @@ class Utils {
|
|
|
6354
6386
|
* @example
|
|
6355
6387
|
* Utils.generateUUID()
|
|
6356
6388
|
*/
|
|
6357
|
-
generateUUID
|
|
6358
|
-
if (typeof globalThis?.crypto?.randomUUID === "function") {
|
|
6359
|
-
return globalThis.crypto.randomUUID();
|
|
6360
|
-
}
|
|
6361
|
-
else {
|
|
6362
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (charStr) {
|
|
6363
|
-
var randomValue = (Math.random() * 16) | 0, randomCharValue = charStr === "x" ? randomValue : (randomValue & 0x3) | 0x8;
|
|
6364
|
-
return randomCharValue.toString(16);
|
|
6365
|
-
});
|
|
6366
|
-
}
|
|
6367
|
-
}
|
|
6389
|
+
generateUUID = GenerateUUID;
|
|
6368
6390
|
}
|
|
6369
6391
|
let utils = new Utils();
|
|
6370
6392
|
|