@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.amd.js +48 -18
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +48 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +48 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +48 -18
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +48 -18
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +48 -18
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Httpx.d.ts +14 -0
- 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 +38 -8
- package/src/Utils.ts +11 -16
- 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() { },
|
|
@@ -3432,13 +3464,20 @@ var Utils = (function () {
|
|
|
3432
3464
|
return source;
|
|
3433
3465
|
}
|
|
3434
3466
|
}
|
|
3467
|
+
if (source == null) {
|
|
3468
|
+
return target;
|
|
3469
|
+
}
|
|
3470
|
+
if (target == null) {
|
|
3471
|
+
target = {};
|
|
3472
|
+
}
|
|
3435
3473
|
if (isAdd) {
|
|
3436
3474
|
for (const sourceKeyName in source) {
|
|
3437
3475
|
const targetKeyName = sourceKeyName;
|
|
3438
3476
|
let targetValue = target[targetKeyName];
|
|
3439
3477
|
let sourceValue = source[sourceKeyName];
|
|
3440
|
-
if (
|
|
3441
|
-
|
|
3478
|
+
if (typeof sourceValue === "object" &&
|
|
3479
|
+
sourceValue != null &&
|
|
3480
|
+
sourceKeyName in target &&
|
|
3442
3481
|
!UtilsContext.isDOM(sourceValue)) {
|
|
3443
3482
|
/* 源端的值是object类型,且不是元素节点 */
|
|
3444
3483
|
target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
@@ -3453,6 +3492,7 @@ var Utils = (function () {
|
|
|
3453
3492
|
let targetValue = target[targetKeyName];
|
|
3454
3493
|
let sourceValue = source[targetKeyName];
|
|
3455
3494
|
if (typeof sourceValue === "object" &&
|
|
3495
|
+
sourceValue != null &&
|
|
3456
3496
|
!UtilsContext.isDOM(sourceValue) &&
|
|
3457
3497
|
Object.keys(sourceValue).length) {
|
|
3458
3498
|
/* 源端的值是object类型,且不是元素节点 */
|
|
@@ -6357,17 +6397,7 @@ var Utils = (function () {
|
|
|
6357
6397
|
* @example
|
|
6358
6398
|
* Utils.generateUUID()
|
|
6359
6399
|
*/
|
|
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
|
-
}
|
|
6400
|
+
generateUUID = GenerateUUID;
|
|
6371
6401
|
}
|
|
6372
6402
|
let utils = new Utils();
|
|
6373
6403
|
|