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