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