@whitesev/utils 2.9.1 → 2.9.3

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.esm.js CHANGED
@@ -5472,7 +5472,7 @@ class DOMUtils {
5472
5472
  }
5473
5473
  const domUtils = new DOMUtils();
5474
5474
 
5475
- const version = "2.9.1";
5475
+ const version = "2.9.3";
5476
5476
 
5477
5477
  class Utils {
5478
5478
  windowApi;
@@ -7632,30 +7632,34 @@ class Utils {
7632
7632
  });
7633
7633
  }
7634
7634
  }
7635
- sortListByProperty(data, getPropertyValueFunc, sortByDesc = true) {
7635
+ sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
7636
7636
  const that = this;
7637
- if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
7637
+ if (typeof getComparePropertyValue !== "function" && typeof getComparePropertyValue !== "string") {
7638
7638
  throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
7639
7639
  }
7640
7640
  if (typeof sortByDesc !== "boolean") {
7641
7641
  throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
7642
7642
  }
7643
- const getObjValue = function (obj) {
7644
- return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
7643
+ const getTargetValue = function (target) {
7644
+ return typeof getComparePropertyValue === "string"
7645
+ ? target[getComparePropertyValue]
7646
+ : getComparePropertyValue(target);
7645
7647
  };
7646
7648
  /**
7647
- * 排序方法
7648
- * @param after_obj
7649
- * @param before_obj
7649
+ * number类型排序方法
7650
+ * @param afterInst
7651
+ * @param beforeInst
7650
7652
  */
7651
- const sortFunc = function (after_obj, before_obj) {
7652
- const beforeValue = getObjValue(before_obj); /* 前 */
7653
- const afterValue = getObjValue(after_obj); /* 后 */
7653
+ const sortFunc = function (afterInst, beforeInst) {
7654
+ const beforeValue = getTargetValue(beforeInst); /* 前 */
7655
+ const afterValue = getTargetValue(afterInst); /* 后 */
7654
7656
  if (sortByDesc) {
7655
- if (afterValue > beforeValue) {
7657
+ // 降序
7658
+ // 5、4、3、2、1
7659
+ if (beforeValue < afterValue) {
7656
7660
  return -1;
7657
7661
  }
7658
- else if (afterValue < beforeValue) {
7662
+ else if (beforeValue > afterValue) {
7659
7663
  return 1;
7660
7664
  }
7661
7665
  else {
@@ -7663,10 +7667,12 @@ class Utils {
7663
7667
  }
7664
7668
  }
7665
7669
  else {
7666
- if (afterValue < beforeValue) {
7670
+ // 升序
7671
+ // 1、2、3、4、5
7672
+ if (beforeValue > afterValue) {
7667
7673
  return -1;
7668
7674
  }
7669
- else if (afterValue > beforeValue) {
7675
+ else if (beforeValue < afterValue) {
7670
7676
  return 1;
7671
7677
  }
7672
7678
  else {
@@ -7675,18 +7681,18 @@ class Utils {
7675
7681
  }
7676
7682
  };
7677
7683
  /**
7678
- * 排序元素方法
7684
+ * 元素排序方法
7679
7685
  * @param nodeList 元素列表
7680
7686
  * @param getNodeListFunc 获取元素列表的函数
7681
7687
  */
7682
7688
  const sortNodeFunc = function (nodeList, getNodeListFunc) {
7683
7689
  const nodeListLength = nodeList.length;
7684
- for (let i = 0; i < nodeListLength - 1; i++) {
7685
- for (let j = 0; j < nodeListLength - 1 - i; j++) {
7686
- const beforeNode = nodeList[j];
7687
- const afterNode = nodeList[j + 1];
7688
- const beforeValue = getObjValue(beforeNode); /* 前 */
7689
- const afterValue = getObjValue(afterNode); /* 后 */
7690
+ for (let index = 0; index < nodeListLength - 1; index++) {
7691
+ for (let index2 = 0; index2 < nodeListLength - 1 - index; index2++) {
7692
+ const beforeNode = nodeList[index2];
7693
+ const afterNode = nodeList[index2 + 1];
7694
+ const beforeValue = getTargetValue(beforeNode); /* 前 */
7695
+ const afterValue = getTargetValue(afterNode); /* 后 */
7690
7696
  if ((sortByDesc == true && beforeValue < afterValue) || (sortByDesc == false && beforeValue > afterValue)) {
7691
7697
  /* 升序/降序 */
7692
7698
  /* 相邻元素两两对比 */
@@ -7709,7 +7715,9 @@ class Utils {
7709
7715
  let getDataFunc = null;
7710
7716
  if (data instanceof Function) {
7711
7717
  getDataFunc = data;
7712
- data = data();
7718
+ const newData = getDataFunc();
7719
+ data = newData;
7720
+ result = newData;
7713
7721
  }
7714
7722
  if (Array.isArray(data)) {
7715
7723
  data.sort(sortFunc);
@@ -8192,10 +8200,12 @@ class Utils {
8192
8200
  }
8193
8201
  createFunction(...args) {
8194
8202
  let isAsync = args[args.length - 1];
8195
- if (typeof isAsync !== "boolean") {
8203
+ if (typeof isAsync === "boolean") {
8204
+ args.splice(args.length - 1, 1);
8205
+ }
8206
+ else {
8196
8207
  isAsync = false;
8197
8208
  }
8198
- args.splice(args.length - 1, 1);
8199
8209
  if (isAsync) {
8200
8210
  const AsyncFunctionConstructor = Object.getPrototypeOf(async function () { }).constructor;
8201
8211
  return new AsyncFunctionConstructor(...args);