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