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