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