@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.amd.js +35 -25
- 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 +35 -25
- 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 +35 -25
- 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 +35 -25
- 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 +35 -25
- 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 +35 -25
- 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 +15 -5
- package/package.json +1 -1
- package/src/Utils.ts +53 -36
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.
|
|
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,
|
|
7641
|
+
sortListByProperty(data, getComparePropertyValue, sortByDesc = true) {
|
|
7642
7642
|
const that = this;
|
|
7643
|
-
if (typeof
|
|
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
|
|
7650
|
-
return typeof
|
|
7649
|
+
const getTargetValue = function (target) {
|
|
7650
|
+
return typeof getComparePropertyValue === "string"
|
|
7651
|
+
? target[getComparePropertyValue]
|
|
7652
|
+
: getComparePropertyValue(target);
|
|
7651
7653
|
};
|
|
7652
7654
|
/**
|
|
7653
|
-
*
|
|
7654
|
-
* @param
|
|
7655
|
-
* @param
|
|
7655
|
+
* number类型排序方法
|
|
7656
|
+
* @param afterInst
|
|
7657
|
+
* @param beforeInst
|
|
7656
7658
|
*/
|
|
7657
|
-
const sortFunc = function (
|
|
7658
|
-
const beforeValue =
|
|
7659
|
-
const afterValue =
|
|
7659
|
+
const sortFunc = function (afterInst, beforeInst) {
|
|
7660
|
+
const beforeValue = getTargetValue(beforeInst); /* 前 */
|
|
7661
|
+
const afterValue = getTargetValue(afterInst); /* 后 */
|
|
7660
7662
|
if (sortByDesc) {
|
|
7661
|
-
|
|
7663
|
+
// 降序
|
|
7664
|
+
// 5、4、3、2、1
|
|
7665
|
+
if (beforeValue < afterValue) {
|
|
7662
7666
|
return -1;
|
|
7663
7667
|
}
|
|
7664
|
-
else if (
|
|
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
|
-
|
|
7676
|
+
// 升序
|
|
7677
|
+
// 1、2、3、4、5
|
|
7678
|
+
if (beforeValue > afterValue) {
|
|
7673
7679
|
return -1;
|
|
7674
7680
|
}
|
|
7675
|
-
else if (
|
|
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
|
|
7691
|
-
for (let
|
|
7692
|
-
const beforeNode = nodeList[
|
|
7693
|
-
const afterNode = nodeList[
|
|
7694
|
-
const beforeValue =
|
|
7695
|
-
const afterValue =
|
|
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
|
-
|
|
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
|
|
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);
|