@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.umd.js CHANGED
@@ -4217,9 +4217,35 @@
4217
4217
 
4218
4218
  class UtilsDictionary {
4219
4219
  items;
4220
- constructor(key, value) {
4220
+ constructor(...args) {
4221
4221
  this.items = new Map();
4222
- if (key != null) {
4222
+ if (args.length === 1) {
4223
+ // 数组|对象
4224
+ const data = args[0];
4225
+ if (Array.isArray(data)) {
4226
+ // 数组
4227
+ // [[1,2], [3,4], ...]
4228
+ for (let index = 0; index < data.length; index++) {
4229
+ const item = data[index];
4230
+ if (Array.isArray(item)) {
4231
+ const [key, value] = item;
4232
+ this.set(key, value);
4233
+ }
4234
+ }
4235
+ }
4236
+ else if (typeof data === "object" && data != null) {
4237
+ // 对象
4238
+ // {1:2, 3:4}
4239
+ for (const key in data) {
4240
+ if (Reflect.has(data, key)) {
4241
+ this.set(key, data[key]);
4242
+ }
4243
+ }
4244
+ }
4245
+ }
4246
+ else if (args.length === 2) {
4247
+ // 键、值
4248
+ const [key, value] = args;
4223
4249
  this.set(key, value);
4224
4250
  }
4225
4251
  }
@@ -4235,7 +4261,7 @@
4235
4261
  get entries() {
4236
4262
  const that = this;
4237
4263
  return function* () {
4238
- const itemKeys = Object.keys(that.getItems());
4264
+ const itemKeys = that.keys();
4239
4265
  for (const keyName of itemKeys) {
4240
4266
  yield [keyName, that.get(keyName)];
4241
4267
  }
@@ -4272,7 +4298,7 @@
4272
4298
  */
4273
4299
  set(key, val) {
4274
4300
  if (key === void 0) {
4275
- throw new Error("Utils.Dictionary().set 参数 key 不能为空");
4301
+ throw new Error("Utils.Dictionary().set 参数 key 不能为undefined");
4276
4302
  }
4277
4303
  this.items.set(key, val);
4278
4304
  }
@@ -5478,7 +5504,7 @@
5478
5504
  }
5479
5505
  const domUtils = new DOMUtils();
5480
5506
 
5481
- const version = "2.9.3";
5507
+ const version = "2.9.4";
5482
5508
 
5483
5509
  class Utils {
5484
5510
  windowApi;