@whitesev/utils 2.9.3 → 2.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.cjs.js CHANGED
@@ -4213,9 +4213,35 @@ class Progress {
4213
4213
 
4214
4214
  class UtilsDictionary {
4215
4215
  items;
4216
- constructor(key, value) {
4216
+ constructor(...args) {
4217
4217
  this.items = new Map();
4218
- if (key != null) {
4218
+ if (args.length === 1) {
4219
+ // 数组|对象
4220
+ const data = args[0];
4221
+ if (Array.isArray(data)) {
4222
+ // 数组
4223
+ // [[1,2], [3,4], ...]
4224
+ for (let index = 0; index < data.length; index++) {
4225
+ const item = data[index];
4226
+ if (Array.isArray(item)) {
4227
+ const [key, value] = item;
4228
+ this.set(key, value);
4229
+ }
4230
+ }
4231
+ }
4232
+ else if (typeof data === "object" && data != null) {
4233
+ // 对象
4234
+ // {1:2, 3:4}
4235
+ for (const key in data) {
4236
+ if (Reflect.has(data, key)) {
4237
+ this.set(key, data[key]);
4238
+ }
4239
+ }
4240
+ }
4241
+ }
4242
+ else if (args.length === 2) {
4243
+ // 键、值
4244
+ const [key, value] = args;
4219
4245
  this.set(key, value);
4220
4246
  }
4221
4247
  }
@@ -4231,7 +4257,7 @@ class UtilsDictionary {
4231
4257
  get entries() {
4232
4258
  const that = this;
4233
4259
  return function* () {
4234
- const itemKeys = Object.keys(that.getItems());
4260
+ const itemKeys = that.keys();
4235
4261
  for (const keyName of itemKeys) {
4236
4262
  yield [keyName, that.get(keyName)];
4237
4263
  }
@@ -4268,7 +4294,7 @@ class UtilsDictionary {
4268
4294
  */
4269
4295
  set(key, val) {
4270
4296
  if (key === void 0) {
4271
- throw new Error("Utils.Dictionary().set 参数 key 不能为空");
4297
+ throw new Error("Utils.Dictionary().set 参数 key 不能为undefined");
4272
4298
  }
4273
4299
  this.items.set(key, val);
4274
4300
  }
@@ -5474,7 +5500,7 @@ class DOMUtils {
5474
5500
  }
5475
5501
  const domUtils = new DOMUtils();
5476
5502
 
5477
- const version = "2.9.3";
5503
+ const version = "2.9.4";
5478
5504
 
5479
5505
  class Utils {
5480
5506
  windowApi;