@whitesev/utils 1.6.0 → 1.6.1
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 +9 -9
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +9 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +9 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +9 -9
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +9 -9
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +9 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Dictionary.d.ts +1 -1
- package/package.json +1 -1
- package/src/Dictionary.ts +9 -9
package/dist/src/Dictionary.d.ts
CHANGED
package/package.json
CHANGED
package/src/Dictionary.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Utils } from "./Utils";
|
|
2
2
|
|
|
3
3
|
class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
4
|
-
|
|
4
|
+
private items: {
|
|
5
5
|
[key: PropertyKey]: V;
|
|
6
6
|
} = {};
|
|
7
7
|
constructor() {}
|
|
@@ -10,7 +10,7 @@ class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
|
10
10
|
* @param key 键
|
|
11
11
|
*/
|
|
12
12
|
has(key: K): boolean {
|
|
13
|
-
return this
|
|
13
|
+
return this.items.hasOwnProperty(key as PropertyKey);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* 检查已有的键中是否以xx开头
|
|
@@ -34,7 +34,7 @@ class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
|
34
34
|
let result = null;
|
|
35
35
|
for (const keyName of allKeys) {
|
|
36
36
|
if (keyName.startsWith(key as string)) {
|
|
37
|
-
result = (this
|
|
37
|
+
result = (this.items as any)[keyName];
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -49,7 +49,7 @@ class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
|
49
49
|
if (key === void 0) {
|
|
50
50
|
throw new Error("Utils.Dictionary().set 参数 key 不能为空");
|
|
51
51
|
}
|
|
52
|
-
(this
|
|
52
|
+
(this.items as any)[key] = val;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* 删除某一个键
|
|
@@ -57,7 +57,7 @@ class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
|
57
57
|
*/
|
|
58
58
|
delete(key: K): boolean {
|
|
59
59
|
if (this.has(key)) {
|
|
60
|
-
Reflect.deleteProperty(this
|
|
60
|
+
Reflect.deleteProperty(this.items, key as string);
|
|
61
61
|
return true;
|
|
62
62
|
}
|
|
63
63
|
return false;
|
|
@@ -85,8 +85,8 @@ class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
|
85
85
|
* 清空字典
|
|
86
86
|
*/
|
|
87
87
|
clear() {
|
|
88
|
-
this
|
|
89
|
-
this
|
|
88
|
+
this.items = void 0 as any;
|
|
89
|
+
this.items = {};
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* 获取字典的长度
|
|
@@ -104,14 +104,14 @@ class UtilsDictionary<K extends PropertyKey, V extends any> {
|
|
|
104
104
|
* 返回字典本身
|
|
105
105
|
*/
|
|
106
106
|
getItems() {
|
|
107
|
-
return this
|
|
107
|
+
return this.items;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* 合并另一个字典
|
|
111
111
|
* @param data 需要合并的字典
|
|
112
112
|
*/
|
|
113
113
|
concat(data: UtilsDictionary<K, V>) {
|
|
114
|
-
this
|
|
114
|
+
this.items = Utils.assign(this.items, data.getItems());
|
|
115
115
|
}
|
|
116
116
|
forEach(
|
|
117
117
|
callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void
|