@whitesev/utils 1.9.0 → 1.9.3
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 +51 -17
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +51 -17
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +51 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +51 -17
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +51 -17
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +51 -17
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Dictionary.d.ts +9 -14
- package/dist/src/Httpx.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1791,6 +1791,14 @@ class Httpx {
|
|
|
1791
1791
|
fetch: details.fetch || this.context.#defaultDetails.fetch,
|
|
1792
1792
|
/* 对象使用深拷贝 */
|
|
1793
1793
|
fetchInit: utils.deepClone(this.context.#defaultDetails.fetchInit),
|
|
1794
|
+
allowInterceptConfig: {
|
|
1795
|
+
beforeRequest: this.context.#defaultDetails
|
|
1796
|
+
.allowInterceptConfig.beforeRequest,
|
|
1797
|
+
afterResponseSuccess: this.context.#defaultDetails
|
|
1798
|
+
.allowInterceptConfig.afterResponseSuccess,
|
|
1799
|
+
afterResponseError: this.context.#defaultDetails
|
|
1800
|
+
.allowInterceptConfig.afterResponseError,
|
|
1801
|
+
},
|
|
1794
1802
|
user: details.user || this.context.#defaultDetails.user,
|
|
1795
1803
|
password: details.password || this.context.#defaultDetails.password,
|
|
1796
1804
|
onabort(...args) {
|
|
@@ -1815,6 +1823,26 @@ class Httpx {
|
|
|
1815
1823
|
that.context.HttpxCallBack.onLoad(details, resolve, reject, args);
|
|
1816
1824
|
},
|
|
1817
1825
|
};
|
|
1826
|
+
// 补全allowInterceptConfig参数
|
|
1827
|
+
if (typeof details.allowInterceptConfig === "boolean") {
|
|
1828
|
+
Object.keys(result.allowInterceptConfig).forEach((keyName) => {
|
|
1829
|
+
result.allowInterceptConfig[keyName] =
|
|
1830
|
+
details.allowInterceptConfig;
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
else {
|
|
1834
|
+
if (typeof details.allowInterceptConfig === "object" &&
|
|
1835
|
+
details.allowInterceptConfig != null) {
|
|
1836
|
+
Object.keys(details.allowInterceptConfig).forEach((keyName) => {
|
|
1837
|
+
let value = details.allowInterceptConfig[keyName];
|
|
1838
|
+
if (keyName in
|
|
1839
|
+
result.allowInterceptConfig &&
|
|
1840
|
+
typeof value === "boolean") {
|
|
1841
|
+
result.allowInterceptConfig[keyName] = value;
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1818
1846
|
if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
|
|
1819
1847
|
result.fetch = true;
|
|
1820
1848
|
}
|
|
@@ -3322,14 +3350,18 @@ const TryCatch = function (...args) {
|
|
|
3322
3350
|
};
|
|
3323
3351
|
|
|
3324
3352
|
class UtilsDictionary {
|
|
3325
|
-
|
|
3326
|
-
constructor() {
|
|
3353
|
+
items = {};
|
|
3354
|
+
constructor(key, value) {
|
|
3355
|
+
if (key != null) {
|
|
3356
|
+
this.set(key, value);
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3327
3359
|
/**
|
|
3328
3360
|
* 检查是否有某一个键
|
|
3329
3361
|
* @param key 键
|
|
3330
3362
|
*/
|
|
3331
3363
|
has(key) {
|
|
3332
|
-
return this
|
|
3364
|
+
return Reflect.has(this.items, key);
|
|
3333
3365
|
}
|
|
3334
3366
|
/**
|
|
3335
3367
|
* 检查已有的键中是否以xx开头
|
|
@@ -3338,7 +3370,7 @@ class UtilsDictionary {
|
|
|
3338
3370
|
startsWith(key) {
|
|
3339
3371
|
let allKeys = this.keys();
|
|
3340
3372
|
for (const keyName of allKeys) {
|
|
3341
|
-
if (keyName.startsWith(key)) {
|
|
3373
|
+
if (String(keyName).startsWith(String(key))) {
|
|
3342
3374
|
return true;
|
|
3343
3375
|
}
|
|
3344
3376
|
}
|
|
@@ -3350,10 +3382,10 @@ class UtilsDictionary {
|
|
|
3350
3382
|
*/
|
|
3351
3383
|
getStartsWith(key) {
|
|
3352
3384
|
let allKeys = this.keys();
|
|
3353
|
-
let result =
|
|
3385
|
+
let result = void 0;
|
|
3354
3386
|
for (const keyName of allKeys) {
|
|
3355
|
-
if (keyName.startsWith(key)) {
|
|
3356
|
-
result = this
|
|
3387
|
+
if (String(keyName).startsWith(String(key))) {
|
|
3388
|
+
result = this.get(keyName);
|
|
3357
3389
|
break;
|
|
3358
3390
|
}
|
|
3359
3391
|
}
|
|
@@ -3368,7 +3400,7 @@ class UtilsDictionary {
|
|
|
3368
3400
|
if (key === void 0) {
|
|
3369
3401
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
3370
3402
|
}
|
|
3371
|
-
this
|
|
3403
|
+
Reflect.set(this.items, key, val);
|
|
3372
3404
|
}
|
|
3373
3405
|
/**
|
|
3374
3406
|
* 删除某一个键
|
|
@@ -3376,17 +3408,18 @@ class UtilsDictionary {
|
|
|
3376
3408
|
*/
|
|
3377
3409
|
delete(key) {
|
|
3378
3410
|
if (this.has(key)) {
|
|
3379
|
-
Reflect.deleteProperty(this
|
|
3380
|
-
return true;
|
|
3411
|
+
return Reflect.deleteProperty(this.items, key);
|
|
3381
3412
|
}
|
|
3382
3413
|
return false;
|
|
3383
3414
|
}
|
|
3384
3415
|
/**
|
|
3385
3416
|
* 获取某个键的值
|
|
3417
|
+
* https://github.com/microsoft/TypeScript/issues/9619
|
|
3418
|
+
* 微软到现在都没有修复has和get的联动
|
|
3386
3419
|
* @param key 键
|
|
3387
3420
|
*/
|
|
3388
3421
|
get(key) {
|
|
3389
|
-
return
|
|
3422
|
+
return Reflect.get(this.items, key);
|
|
3390
3423
|
}
|
|
3391
3424
|
/**
|
|
3392
3425
|
* 返回字典中的所有值
|
|
@@ -3395,7 +3428,7 @@ class UtilsDictionary {
|
|
|
3395
3428
|
let resultList = [];
|
|
3396
3429
|
for (let prop in this.getItems()) {
|
|
3397
3430
|
if (this.has(prop)) {
|
|
3398
|
-
resultList.push(this.
|
|
3431
|
+
resultList.push(this.get(prop));
|
|
3399
3432
|
}
|
|
3400
3433
|
}
|
|
3401
3434
|
return resultList;
|
|
@@ -3404,8 +3437,8 @@ class UtilsDictionary {
|
|
|
3404
3437
|
* 清空字典
|
|
3405
3438
|
*/
|
|
3406
3439
|
clear() {
|
|
3407
|
-
this
|
|
3408
|
-
this
|
|
3440
|
+
this.items = null;
|
|
3441
|
+
this.items = {};
|
|
3409
3442
|
}
|
|
3410
3443
|
/**
|
|
3411
3444
|
* 获取字典的长度
|
|
@@ -3417,20 +3450,21 @@ class UtilsDictionary {
|
|
|
3417
3450
|
* 获取字典所有的键
|
|
3418
3451
|
*/
|
|
3419
3452
|
keys() {
|
|
3420
|
-
return
|
|
3453
|
+
return Reflect.ownKeys(this.items);
|
|
3421
3454
|
}
|
|
3422
3455
|
/**
|
|
3423
3456
|
* 返回字典本身
|
|
3424
3457
|
*/
|
|
3425
3458
|
getItems() {
|
|
3426
|
-
|
|
3459
|
+
// @ts-ignore
|
|
3460
|
+
return this.items;
|
|
3427
3461
|
}
|
|
3428
3462
|
/**
|
|
3429
3463
|
* 合并另一个字典
|
|
3430
3464
|
* @param data 需要合并的字典
|
|
3431
3465
|
*/
|
|
3432
3466
|
concat(data) {
|
|
3433
|
-
this
|
|
3467
|
+
this.items = utils.assign(this.items, data.getItems());
|
|
3434
3468
|
}
|
|
3435
3469
|
forEach(callbackfn) {
|
|
3436
3470
|
for (const key in this.getItems()) {
|