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