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