@whitesev/utils 2.3.5 → 2.3.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.
@@ -434,7 +434,9 @@ declare class Utils {
434
434
  getMaxValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
435
435
  /**
436
436
  * 获取页面中最大的z-index的元素信息
437
- * @param deviation 获取最大的z-index值的偏移,默认是+1
437
+ * @param deviation 获取最大的z-index值的偏移,默认是1
438
+ * @param node 进行判断的元素,默认是document
439
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
438
440
  * @example
439
441
  * Utils.getMaxZIndexNodeInfo();
440
442
  * > {
@@ -442,18 +444,20 @@ declare class Utils {
442
444
  * zIndex: 1001
443
445
  * }
444
446
  **/
445
- getMaxZIndexNodeInfo(deviation?: number): {
447
+ getMaxZIndexNodeInfo(deviation?: number, target?: Element | ShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): {
446
448
  node: Element;
447
449
  zIndex: number;
448
450
  };
449
451
  /**
450
452
  * 获取页面中最大的z-index
451
- * @param deviation 获取最大的z-index值的偏移,默认是+1
453
+ * @param deviation 获取最大的z-index值的偏移,默认是1
454
+ * @param node 进行判断的元素,默认是document
455
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
452
456
  * @example
453
457
  * Utils.getMaxZIndex();
454
458
  * > 1001
455
459
  **/
456
- getMaxZIndex(deviation?: number): number;
460
+ getMaxZIndex(deviation?: number, target?: Element | DocumentOrShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): number;
457
461
  /**
458
462
  * 获取最小值
459
463
  * @example
@@ -959,7 +963,7 @@ declare class Utils {
959
963
  * Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
960
964
  * > ['jsonToArray', 'Array']
961
965
  **/
962
- parseObjectToArray(target: any): any;
966
+ parseObjectToArray<T extends any>(target: T): T[keyof T][];
963
967
  /**
964
968
  * 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
965
969
  * @example
@@ -1010,7 +1014,7 @@ declare class Utils {
1010
1014
  * Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
1011
1015
  * > '数组内数据部分字段合并成字符串->mergeToString'
1012
1016
  **/
1013
- mergeArrayToString(data: any[], handleFunc?: (val: any) => any): string;
1017
+ mergeArrayToString<T extends any>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string;
1014
1018
  /**
1015
1019
  * 监听页面元素改变并处理
1016
1020
  * @param target 需要监听的元素,如果不存在,可以等待它出现
@@ -1138,7 +1142,7 @@ declare class Utils {
1138
1142
  * Utils.parseInt(["aaaaaaa"],"aa");
1139
1143
  * > NaN
1140
1144
  **/
1141
- parseInt(matchList?: any[], defaultValue?: number): number;
1145
+ parseInt(matchList?: any[] | null | undefined | RegExpMatchArray, defaultValue?: number): number;
1142
1146
  /**
1143
1147
  * blob转File对象
1144
1148
  * @param blobUrl 需要转换的blob的链接
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Utils.ts CHANGED
@@ -53,7 +53,7 @@ class Utils {
53
53
  this.windowApi = new WindowApi(option);
54
54
  }
55
55
  /** 版本号 */
56
- version = "2024.9.28";
56
+ version = "2024.10.19";
57
57
 
58
58
  /**
59
59
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -1228,7 +1228,9 @@ class Utils {
1228
1228
  }
1229
1229
  /**
1230
1230
  * 获取页面中最大的z-index的元素信息
1231
- * @param deviation 获取最大的z-index值的偏移,默认是+1
1231
+ * @param deviation 获取最大的z-index值的偏移,默认是1
1232
+ * @param node 进行判断的元素,默认是document
1233
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
1232
1234
  * @example
1233
1235
  * Utils.getMaxZIndexNodeInfo();
1234
1236
  * > {
@@ -1236,11 +1238,23 @@ class Utils {
1236
1238
  * zIndex: 1001
1237
1239
  * }
1238
1240
  **/
1239
- getMaxZIndexNodeInfo(deviation?: number): {
1241
+ getMaxZIndexNodeInfo(
1242
+ deviation?: number,
1243
+ target?: Element | ShadowRoot | Document,
1244
+ ignoreCallBack?: (
1245
+ $ele: Element | HTMLElement | ShadowRoot
1246
+ ) => boolean | void
1247
+ ): {
1240
1248
  node: Element;
1241
1249
  zIndex: number;
1242
1250
  };
1243
- getMaxZIndexNodeInfo(deviation = 1): {
1251
+ getMaxZIndexNodeInfo(
1252
+ deviation = 1,
1253
+ target: Element | ShadowRoot | Document = this.windowApi.document,
1254
+ ignoreCallBack?: (
1255
+ $ele: Element | HTMLElement | ShadowRoot
1256
+ ) => boolean | void
1257
+ ): {
1244
1258
  node: Element;
1245
1259
  zIndex: number;
1246
1260
  } {
@@ -1268,6 +1282,12 @@ class Utils {
1268
1282
  * @param $ele
1269
1283
  */
1270
1284
  function queryMaxZIndex($ele: Element) {
1285
+ if (typeof ignoreCallBack === "function") {
1286
+ let ignoreResult = ignoreCallBack($ele);
1287
+ if (typeof ignoreResult === "boolean" && !ignoreResult) {
1288
+ return;
1289
+ }
1290
+ }
1271
1291
  /** 元素的样式 */
1272
1292
  const nodeStyle = UtilsContext.windowApi.window.getComputedStyle($ele);
1273
1293
  /* 不对position为static和display为none的元素进行获取它们的z-index */
@@ -1288,7 +1308,7 @@ class Utils {
1288
1308
  }
1289
1309
  }
1290
1310
  }
1291
- this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
1311
+ target.querySelectorAll("*").forEach(($ele, index) => {
1292
1312
  queryMaxZIndex($ele);
1293
1313
  });
1294
1314
  zIndex += deviation;
@@ -1303,14 +1323,28 @@ class Utils {
1303
1323
  }
1304
1324
  /**
1305
1325
  * 获取页面中最大的z-index
1306
- * @param deviation 获取最大的z-index值的偏移,默认是+1
1326
+ * @param deviation 获取最大的z-index值的偏移,默认是1
1327
+ * @param node 进行判断的元素,默认是document
1328
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
1307
1329
  * @example
1308
1330
  * Utils.getMaxZIndex();
1309
1331
  * > 1001
1310
1332
  **/
1311
- getMaxZIndex(deviation?: number): number;
1312
- getMaxZIndex(deviation = 1): number {
1313
- return this.getMaxZIndexNodeInfo(deviation).zIndex;
1333
+ getMaxZIndex(
1334
+ deviation?: number,
1335
+ target?: Element | DocumentOrShadowRoot | Document,
1336
+ ignoreCallBack?: (
1337
+ $ele: Element | HTMLElement | ShadowRoot
1338
+ ) => boolean | void
1339
+ ): number;
1340
+ getMaxZIndex(
1341
+ deviation = 1,
1342
+ target: Element | ShadowRoot | Document = this.windowApi.document,
1343
+ ignoreCallBack?: (
1344
+ $ele: Element | HTMLElement | ShadowRoot
1345
+ ) => boolean | void
1346
+ ): number {
1347
+ return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
1314
1348
  }
1315
1349
  /**
1316
1350
  * 获取最小值
@@ -2344,16 +2378,16 @@ class Utils {
2344
2378
  * Utils.parseObjectToArray({"工具类":"jsonToArray","return","Array"});
2345
2379
  * > ['jsonToArray', 'Array']
2346
2380
  **/
2347
- parseObjectToArray(target: any): any;
2348
- parseObjectToArray(target: any): any {
2381
+ parseObjectToArray<T extends any>(target: T): T[keyof T][];
2382
+ parseObjectToArray<T extends any>(target: T) {
2349
2383
  if (typeof target !== "object") {
2350
2384
  throw new Error(
2351
2385
  "Utils.parseObjectToArray 参数 target 必须为 object 类型"
2352
2386
  );
2353
2387
  }
2354
- let result: any[] = [];
2355
- Object.keys(target).forEach(function (keyName) {
2356
- result = result.concat(target[keyName]);
2388
+ let result: T[keyof T][] = [];
2389
+ Object.keys(target!).forEach(function (keyName) {
2390
+ result = result.concat(target![keyName as any as keyof T]);
2357
2391
  });
2358
2392
  return result;
2359
2393
  }
@@ -2407,8 +2441,14 @@ class Utils {
2407
2441
  * Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
2408
2442
  * > '数组内数据部分字段合并成字符串->mergeToString'
2409
2443
  **/
2410
- mergeArrayToString(data: any[], handleFunc?: (val: any) => any): string;
2411
- mergeArrayToString(data: any[], handleFunc?: (val: any) => any): string {
2444
+ mergeArrayToString<T extends any>(
2445
+ data: T[],
2446
+ handleFunc?: ((val: T) => T) | keyof T
2447
+ ): string;
2448
+ mergeArrayToString<T extends any>(
2449
+ data: T[],
2450
+ handleFunc?: ((val: T) => T) | keyof T
2451
+ ): string {
2412
2452
  if (!(data instanceof Array)) {
2413
2453
  throw new Error("Utils.mergeArrayToString 参数 data 必须为 Array 类型");
2414
2454
  }
@@ -2423,7 +2463,7 @@ class Utils {
2423
2463
  });
2424
2464
  } else {
2425
2465
  data.forEach((item) => {
2426
- Object.values(item)
2466
+ Object.values(item as any)
2427
2467
  .filter((item2) => typeof item2 === "string")
2428
2468
  .forEach((item3) => {
2429
2469
  content += item3;
@@ -2880,7 +2920,10 @@ class Utils {
2880
2920
  * Utils.parseInt(["aaaaaaa"],"aa");
2881
2921
  * > NaN
2882
2922
  **/
2883
- parseInt(matchList?: any[], defaultValue?: number): number;
2923
+ parseInt(
2924
+ matchList?: any[] | null | undefined | RegExpMatchArray,
2925
+ defaultValue?: number
2926
+ ): number;
2884
2927
  parseInt(matchList: any[] = [], defaultValue = 0): number {
2885
2928
  if (matchList == null) {
2886
2929
  return parseInt(defaultValue.toString());