@whitesev/utils 1.9.2 → 1.9.4

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
@@ -3352,14 +3352,18 @@ define((function () { 'use strict';
3352
3352
  };
3353
3353
 
3354
3354
  class UtilsDictionary {
3355
- #items = {};
3356
- constructor() { }
3355
+ items = {};
3356
+ constructor(key, value) {
3357
+ if (key != null) {
3358
+ this.set(key, value);
3359
+ }
3360
+ }
3357
3361
  /**
3358
3362
  * 检查是否有某一个键
3359
3363
  * @param key 键
3360
3364
  */
3361
3365
  has(key) {
3362
- return this.#items.hasOwnProperty(key);
3366
+ return Reflect.has(this.items, key);
3363
3367
  }
3364
3368
  /**
3365
3369
  * 检查已有的键中是否以xx开头
@@ -3368,7 +3372,7 @@ define((function () { 'use strict';
3368
3372
  startsWith(key) {
3369
3373
  let allKeys = this.keys();
3370
3374
  for (const keyName of allKeys) {
3371
- if (keyName.startsWith(key)) {
3375
+ if (String(keyName).startsWith(String(key))) {
3372
3376
  return true;
3373
3377
  }
3374
3378
  }
@@ -3380,10 +3384,10 @@ define((function () { 'use strict';
3380
3384
  */
3381
3385
  getStartsWith(key) {
3382
3386
  let allKeys = this.keys();
3383
- let result = null;
3387
+ let result = void 0;
3384
3388
  for (const keyName of allKeys) {
3385
- if (keyName.startsWith(key)) {
3386
- result = this.#items[keyName];
3389
+ if (String(keyName).startsWith(String(key))) {
3390
+ result = this.get(keyName);
3387
3391
  break;
3388
3392
  }
3389
3393
  }
@@ -3398,7 +3402,7 @@ define((function () { 'use strict';
3398
3402
  if (key === void 0) {
3399
3403
  throw new Error("Utils.Dictionary().set 参数 key 不能为空");
3400
3404
  }
3401
- this.#items[key] = val;
3405
+ Reflect.set(this.items, key, val);
3402
3406
  }
3403
3407
  /**
3404
3408
  * 删除某一个键
@@ -3406,17 +3410,18 @@ define((function () { 'use strict';
3406
3410
  */
3407
3411
  delete(key) {
3408
3412
  if (this.has(key)) {
3409
- Reflect.deleteProperty(this.#items, key);
3410
- return true;
3413
+ return Reflect.deleteProperty(this.items, key);
3411
3414
  }
3412
3415
  return false;
3413
3416
  }
3414
3417
  /**
3415
3418
  * 获取某个键的值
3419
+ * https://github.com/microsoft/TypeScript/issues/9619
3420
+ * 微软到现在都没有修复has和get的联动
3416
3421
  * @param key 键
3417
3422
  */
3418
3423
  get(key) {
3419
- return this.has(key) ? this.getItems()[key] : void 0;
3424
+ return Reflect.get(this.items, key);
3420
3425
  }
3421
3426
  /**
3422
3427
  * 返回字典中的所有值
@@ -3425,7 +3430,7 @@ define((function () { 'use strict';
3425
3430
  let resultList = [];
3426
3431
  for (let prop in this.getItems()) {
3427
3432
  if (this.has(prop)) {
3428
- resultList.push(this.getItems()[prop]);
3433
+ resultList.push(this.get(prop));
3429
3434
  }
3430
3435
  }
3431
3436
  return resultList;
@@ -3434,8 +3439,8 @@ define((function () { 'use strict';
3434
3439
  * 清空字典
3435
3440
  */
3436
3441
  clear() {
3437
- this.#items = void 0;
3438
- this.#items = {};
3442
+ this.items = null;
3443
+ this.items = {};
3439
3444
  }
3440
3445
  /**
3441
3446
  * 获取字典的长度
@@ -3447,20 +3452,21 @@ define((function () { 'use strict';
3447
3452
  * 获取字典所有的键
3448
3453
  */
3449
3454
  keys() {
3450
- return Object.keys(this.getItems());
3455
+ return Reflect.ownKeys(this.items);
3451
3456
  }
3452
3457
  /**
3453
3458
  * 返回字典本身
3454
3459
  */
3455
3460
  getItems() {
3456
- return this.#items;
3461
+ // @ts-ignore
3462
+ return this.items;
3457
3463
  }
3458
3464
  /**
3459
3465
  * 合并另一个字典
3460
3466
  * @param data 需要合并的字典
3461
3467
  */
3462
3468
  concat(data) {
3463
- this.#items = utils.assign(this.#items, data.getItems());
3469
+ this.items = utils.assign(this.items, data.getItems());
3464
3470
  }
3465
3471
  forEach(callbackfn) {
3466
3472
  for (const key in this.getItems()) {