@whitesev/utils 2.7.5 → 2.7.7

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