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