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