@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.iife.js
CHANGED
|
@@ -5475,7 +5475,7 @@ var Utils = (function () {
|
|
|
5475
5475
|
}
|
|
5476
5476
|
const domUtils = new DOMUtils();
|
|
5477
5477
|
|
|
5478
|
-
const version = "2.9.
|
|
5478
|
+
const version = "2.9.3";
|
|
5479
5479
|
|
|
5480
5480
|
class Utils {
|
|
5481
5481
|
windowApi;
|
|
@@ -7635,30 +7635,34 @@ var Utils = (function () {
|
|
|
7635
7635
|
});
|
|
7636
7636
|
}
|
|
7637
7637
|
}
|
|
7638
|
-
sortListByProperty(data,
|
|
7638
|
+
sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
|
|
7639
7639
|
const that = this;
|
|
7640
|
-
if (typeof
|
|
7640
|
+
if (typeof getComparePropertyValue !== "function" && typeof getComparePropertyValue !== "string") {
|
|
7641
7641
|
throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
|
|
7642
7642
|
}
|
|
7643
7643
|
if (typeof sortByDesc !== "boolean") {
|
|
7644
7644
|
throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
|
|
7645
7645
|
}
|
|
7646
|
-
const
|
|
7647
|
-
return typeof
|
|
7646
|
+
const getTargetValue = function (target) {
|
|
7647
|
+
return typeof getComparePropertyValue === "string"
|
|
7648
|
+
? target[getComparePropertyValue]
|
|
7649
|
+
: getComparePropertyValue(target);
|
|
7648
7650
|
};
|
|
7649
7651
|
/**
|
|
7650
|
-
*
|
|
7651
|
-
* @param
|
|
7652
|
-
* @param
|
|
7652
|
+
* number类型排序方法
|
|
7653
|
+
* @param afterInst
|
|
7654
|
+
* @param beforeInst
|
|
7653
7655
|
*/
|
|
7654
|
-
const sortFunc = function (
|
|
7655
|
-
const beforeValue =
|
|
7656
|
-
const afterValue =
|
|
7656
|
+
const sortFunc = function (afterInst, beforeInst) {
|
|
7657
|
+
const beforeValue = getTargetValue(beforeInst); /* 前 */
|
|
7658
|
+
const afterValue = getTargetValue(afterInst); /* 后 */
|
|
7657
7659
|
if (sortByDesc) {
|
|
7658
|
-
|
|
7660
|
+
// 降序
|
|
7661
|
+
// 5、4、3、2、1
|
|
7662
|
+
if (beforeValue < afterValue) {
|
|
7659
7663
|
return -1;
|
|
7660
7664
|
}
|
|
7661
|
-
else if (
|
|
7665
|
+
else if (beforeValue > afterValue) {
|
|
7662
7666
|
return 1;
|
|
7663
7667
|
}
|
|
7664
7668
|
else {
|
|
@@ -7666,10 +7670,12 @@ var Utils = (function () {
|
|
|
7666
7670
|
}
|
|
7667
7671
|
}
|
|
7668
7672
|
else {
|
|
7669
|
-
|
|
7673
|
+
// 升序
|
|
7674
|
+
// 1、2、3、4、5
|
|
7675
|
+
if (beforeValue > afterValue) {
|
|
7670
7676
|
return -1;
|
|
7671
7677
|
}
|
|
7672
|
-
else if (
|
|
7678
|
+
else if (beforeValue < afterValue) {
|
|
7673
7679
|
return 1;
|
|
7674
7680
|
}
|
|
7675
7681
|
else {
|
|
@@ -7678,18 +7684,18 @@ var Utils = (function () {
|
|
|
7678
7684
|
}
|
|
7679
7685
|
};
|
|
7680
7686
|
/**
|
|
7681
|
-
*
|
|
7687
|
+
* 元素排序方法
|
|
7682
7688
|
* @param nodeList 元素列表
|
|
7683
7689
|
* @param getNodeListFunc 获取元素列表的函数
|
|
7684
7690
|
*/
|
|
7685
7691
|
const sortNodeFunc = function (nodeList, getNodeListFunc) {
|
|
7686
7692
|
const nodeListLength = nodeList.length;
|
|
7687
|
-
for (let
|
|
7688
|
-
for (let
|
|
7689
|
-
const beforeNode = nodeList[
|
|
7690
|
-
const afterNode = nodeList[
|
|
7691
|
-
const beforeValue =
|
|
7692
|
-
const afterValue =
|
|
7693
|
+
for (let index = 0; index < nodeListLength - 1; index++) {
|
|
7694
|
+
for (let index2 = 0; index2 < nodeListLength - 1 - index; index2++) {
|
|
7695
|
+
const beforeNode = nodeList[index2];
|
|
7696
|
+
const afterNode = nodeList[index2 + 1];
|
|
7697
|
+
const beforeValue = getTargetValue(beforeNode); /* 前 */
|
|
7698
|
+
const afterValue = getTargetValue(afterNode); /* 后 */
|
|
7693
7699
|
if ((sortByDesc == true && beforeValue < afterValue) || (sortByDesc == false && beforeValue > afterValue)) {
|
|
7694
7700
|
/* 升序/降序 */
|
|
7695
7701
|
/* 相邻元素两两对比 */
|
|
@@ -7712,7 +7718,9 @@ var Utils = (function () {
|
|
|
7712
7718
|
let getDataFunc = null;
|
|
7713
7719
|
if (data instanceof Function) {
|
|
7714
7720
|
getDataFunc = data;
|
|
7715
|
-
|
|
7721
|
+
const newData = getDataFunc();
|
|
7722
|
+
data = newData;
|
|
7723
|
+
result = newData;
|
|
7716
7724
|
}
|
|
7717
7725
|
if (Array.isArray(data)) {
|
|
7718
7726
|
data.sort(sortFunc);
|