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