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