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