@whitesev/utils 2.9.2 → 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.amd.js +31 -23
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +31 -23
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +31 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +31 -23
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +31 -23
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +31 -23
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/Utils.d.ts +5 -2
- package/package.json +1 -1
- package/src/Utils.ts +44 -29
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.
|
|
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,
|
|
7635
|
+
sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
|
|
7636
7636
|
const that = this;
|
|
7637
|
-
if (typeof
|
|
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
|
|
7644
|
-
return typeof
|
|
7643
|
+
const getTargetValue = function (target) {
|
|
7644
|
+
return typeof getComparePropertyValue === "string"
|
|
7645
|
+
? target[getComparePropertyValue]
|
|
7646
|
+
: getComparePropertyValue(target);
|
|
7645
7647
|
};
|
|
7646
7648
|
/**
|
|
7647
|
-
*
|
|
7648
|
-
* @param
|
|
7649
|
-
* @param
|
|
7649
|
+
* number类型排序方法
|
|
7650
|
+
* @param afterInst
|
|
7651
|
+
* @param beforeInst
|
|
7650
7652
|
*/
|
|
7651
|
-
const sortFunc = function (
|
|
7652
|
-
const beforeValue =
|
|
7653
|
-
const afterValue =
|
|
7653
|
+
const sortFunc = function (afterInst, beforeInst) {
|
|
7654
|
+
const beforeValue = getTargetValue(beforeInst); /* 前 */
|
|
7655
|
+
const afterValue = getTargetValue(afterInst); /* 后 */
|
|
7654
7656
|
if (sortByDesc) {
|
|
7655
|
-
|
|
7657
|
+
// 降序
|
|
7658
|
+
// 5、4、3、2、1
|
|
7659
|
+
if (beforeValue < afterValue) {
|
|
7656
7660
|
return -1;
|
|
7657
7661
|
}
|
|
7658
|
-
else if (
|
|
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
|
-
|
|
7670
|
+
// 升序
|
|
7671
|
+
// 1、2、3、4、5
|
|
7672
|
+
if (beforeValue > afterValue) {
|
|
7667
7673
|
return -1;
|
|
7668
7674
|
}
|
|
7669
|
-
else if (
|
|
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
|
|
7685
|
-
for (let
|
|
7686
|
-
const beforeNode = nodeList[
|
|
7687
|
-
const afterNode = nodeList[
|
|
7688
|
-
const beforeValue =
|
|
7689
|
-
const afterValue =
|
|
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
|
-
|
|
7718
|
+
const newData = getDataFunc();
|
|
7719
|
+
data = newData;
|
|
7720
|
+
result = newData;
|
|
7713
7721
|
}
|
|
7714
7722
|
if (Array.isArray(data)) {
|
|
7715
7723
|
data.sort(sortFunc);
|