@whitesev/utils 1.5.9 → 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.
@@ -1,5 +1,5 @@
1
1
  declare class UtilsDictionary<K extends PropertyKey, V extends any> {
2
- #private;
2
+ private items;
3
3
  constructor();
4
4
  /**
5
5
  * 检查是否有某一个键
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "1.5.9",
3
+ "version": "1.6.1",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/node/index.esm.js",
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
- #items: {
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.#items.hasOwnProperty(key as PropertyKey);
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.#items as any)[keyName];
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.#items as any)[key] = val;
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.#items, key as string);
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.#items = void 0 as any;
89
- this.#items = {};
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.#items;
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.#items = Utils.assign(this.#items, data.getItems());
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
package/src/Utils.ts CHANGED
@@ -119,14 +119,21 @@ class Utils {
119
119
  return source;
120
120
  }
121
121
  }
122
+ if (source == null) {
123
+ return target;
124
+ }
125
+ if (target == null) {
126
+ target = {};
127
+ }
122
128
  if (isAdd) {
123
129
  for (const sourceKeyName in source) {
124
130
  const targetKeyName = sourceKeyName;
125
131
  let targetValue = (target as any)[targetKeyName];
126
132
  let sourceValue = (source as any)[sourceKeyName];
127
133
  if (
128
- sourceKeyName in target &&
129
134
  typeof sourceValue === "object" &&
135
+ sourceValue != null &&
136
+ sourceKeyName in target &&
130
137
  !UtilsContext.isDOM(sourceValue)
131
138
  ) {
132
139
  /* 源端的值是object类型,且不是元素节点 */
@@ -146,6 +153,7 @@ class Utils {
146
153
  let sourceValue = (source as any)[targetKeyName];
147
154
  if (
148
155
  typeof sourceValue === "object" &&
156
+ sourceValue != null &&
149
157
  !UtilsContext.isDOM(sourceValue) &&
150
158
  Object.keys(sourceValue).length
151
159
  ) {