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