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