@whitesev/utils 2.7.5 → 2.7.6

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.esm.js CHANGED
@@ -4205,7 +4205,7 @@ class Progress {
4205
4205
  class UtilsDictionary {
4206
4206
  items;
4207
4207
  constructor(key, value) {
4208
- this.items = {};
4208
+ this.items = new Map();
4209
4209
  if (key != null) {
4210
4210
  this.set(key, value);
4211
4211
  }
@@ -4242,35 +4242,16 @@ class UtilsDictionary {
4242
4242
  * @param key 键
4243
4243
  */
4244
4244
  has(key) {
4245
- return Reflect.has(this.items, key);
4245
+ return this.items.has(key);
4246
4246
  }
4247
4247
  /**
4248
- * 检查已有的键中是否以xx开头
4249
- * @param key 需要匹配的键
4250
- */
4251
- startsWith(key) {
4252
- let allKeys = this.keys();
4253
- for (const keyName of allKeys) {
4254
- if (String(keyName).startsWith(String(key))) {
4255
- return true;
4256
- }
4257
- }
4258
- return false;
4259
- }
4260
- /**
4261
- * 获取以xx开头的键的值
4262
- * @param key 需要匹配的键
4248
+ * 获取某个键的值
4249
+ * https://github.com/microsoft/TypeScript/issues/9619
4250
+ * 微软到现在都没有实现has和get的联动
4251
+ * @param key
4263
4252
  */
4264
- getStartsWith(key) {
4265
- let allKeys = this.keys();
4266
- let result = void 0;
4267
- for (const keyName of allKeys) {
4268
- if (String(keyName).startsWith(String(key))) {
4269
- result = this.get(keyName);
4270
- break;
4271
- }
4272
- }
4273
- return result;
4253
+ get(key) {
4254
+ return this.items.get(key);
4274
4255
  }
4275
4256
  /**
4276
4257
  * 为字典添加某一个值
@@ -4281,57 +4262,44 @@ class UtilsDictionary {
4281
4262
  if (key === void 0) {
4282
4263
  throw new Error("Utils.Dictionary().set 参数 key 不能为空");
4283
4264
  }
4284
- Reflect.set(this.items, key, val);
4265
+ this.items.set(key, val);
4285
4266
  }
4286
4267
  /**
4287
4268
  * 删除某一个键
4288
4269
  * @param key 键
4270
+ * @returns
4271
+ * + true:键存在且成功删除
4272
+ * + false:键不存在
4289
4273
  */
4290
4274
  delete(key) {
4291
4275
  if (this.has(key)) {
4292
- return Reflect.deleteProperty(this.items, key);
4276
+ return this.items.delete(key);
4293
4277
  }
4294
4278
  return false;
4295
4279
  }
4296
4280
  /**
4297
- * 获取某个键的值
4298
- * https://github.com/microsoft/TypeScript/issues/9619
4299
- * 微软到现在都没有修复has和get的联动
4300
- * @param key 键
4281
+ * 获取字典所有的键
4301
4282
  */
4302
- get(key) {
4303
- return Reflect.get(this.items, key);
4283
+ keys() {
4284
+ return this.items.keys().toArray();
4304
4285
  }
4305
4286
  /**
4306
4287
  * 返回字典中的所有值
4307
4288
  */
4308
4289
  values() {
4309
- let resultList = [];
4310
- for (let prop in this.getItems()) {
4311
- if (this.has(prop)) {
4312
- resultList.push(this.get(prop));
4313
- }
4314
- }
4315
- return resultList;
4290
+ return this.items.values().toArray();
4316
4291
  }
4317
4292
  /**
4318
4293
  * 清空字典
4319
4294
  */
4320
4295
  clear() {
4321
- this.items = null;
4322
- this.items = {};
4296
+ this.items.clear();
4323
4297
  }
4324
4298
  /**
4325
4299
  * 获取字典的长度
4326
4300
  */
4327
4301
  size() {
4328
- return Object.keys(this.getItems()).length;
4329
- }
4330
- /**
4331
- * 获取字典所有的键
4332
- */
4333
- keys() {
4334
- return Reflect.ownKeys(this.items);
4302
+ return this.items.size;
4335
4303
  }
4336
4304
  /**
4337
4305
  * 返回字典本身
@@ -4344,16 +4312,46 @@ class UtilsDictionary {
4344
4312
  * @param data 需要合并的字典
4345
4313
  */
4346
4314
  concat(data) {
4347
- this.items = commonUtil.assign(this.items, data.getItems());
4315
+ data.forEach((value, key) => {
4316
+ this.items.set(key, value);
4317
+ });
4348
4318
  }
4349
4319
  /**
4350
4320
  * 迭代字典
4351
4321
  * @param callbackfn 回调函数
4352
4322
  */
4353
4323
  forEach(callbackfn) {
4354
- for (const key in this.getItems()) {
4355
- callbackfn(this.get(key), key, this.getItems());
4324
+ this.items.forEach((value, key, self) => {
4325
+ callbackfn(value, key, this);
4326
+ });
4327
+ }
4328
+ /**
4329
+ * 检查已有的键中是否以xx开头
4330
+ * @param key 需要匹配的键
4331
+ */
4332
+ startsWith(key) {
4333
+ const keys = this.keys();
4334
+ for (const keyName of keys) {
4335
+ if (String(keyName).startsWith(key)) {
4336
+ return true;
4337
+ }
4356
4338
  }
4339
+ return false;
4340
+ }
4341
+ /**
4342
+ * 获取以xx开头的键的值
4343
+ * @param key 需要匹配的键
4344
+ */
4345
+ getStartsWith(key) {
4346
+ let result = void 0;
4347
+ const keys = this.keys();
4348
+ for (const keyName of keys) {
4349
+ if (String(keyName).startsWith(String(key))) {
4350
+ result = this.get(keyName);
4351
+ break;
4352
+ }
4353
+ }
4354
+ return result;
4357
4355
  }
4358
4356
  }
4359
4357
 
@@ -5475,7 +5473,7 @@ class Utils {
5475
5473
  this.windowApi = new WindowApi(option);
5476
5474
  }
5477
5475
  /** 版本号 */
5478
- version = "2025.8.21";
5476
+ version = "2025.9.8";
5479
5477
  addStyle(cssText) {
5480
5478
  if (typeof cssText !== "string") {
5481
5479
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -5805,19 +5803,19 @@ class Utils {
5805
5803
  }
5806
5804
  else {
5807
5805
  let textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
5808
- for (let ele of textElement) {
5809
- if (ele.textContent.includes(text)) {
5806
+ for (let $child of textElement) {
5807
+ if ($child.textContent.includes(text)) {
5810
5808
  let filterResult = typeof filter === "function" ? filter(element) : false;
5811
5809
  if (!filterResult) {
5812
- yield ele;
5810
+ yield $child;
5813
5811
  }
5814
5812
  }
5815
5813
  }
5816
5814
  }
5817
5815
  }
5818
5816
  for (let index = 0; index < element.children.length; index++) {
5819
- let childElement = element.children[index];
5820
- yield* that.findElementsWithText(childElement, text, filter);
5817
+ let $child = element.children[index];
5818
+ yield* that.findElementsWithText($child, text, filter);
5821
5819
  }
5822
5820
  }
5823
5821
  /**