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