qmwts 1.1.75 → 1.1.77
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.
|
@@ -26,10 +26,10 @@ declare const _default: {
|
|
|
26
26
|
/**
|
|
27
27
|
* 根据数组元素中的某一属性进行去重
|
|
28
28
|
* @param array
|
|
29
|
-
* @param
|
|
29
|
+
* @param value 获取元素唯一标识的函数
|
|
30
30
|
* @param override 遇到重复元素是否覆盖
|
|
31
31
|
*/
|
|
32
|
-
uniqueBy<T>(array: T[] | undefined,
|
|
32
|
+
uniqueBy<T, K = unknown>(array: T[] | undefined, value: (item: T) => K, override?: boolean): T[];
|
|
33
33
|
sort<T>(array: T[], order: "asc" | "desc", ...values: ((item: T) => number)[]): void;
|
|
34
34
|
};
|
|
35
35
|
export default _default;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const object_utils_1 = require("./object-utils");
|
|
4
3
|
exports.default = {
|
|
5
4
|
/**
|
|
6
5
|
* 数组转化为树形结构
|
|
@@ -87,18 +86,19 @@ exports.default = {
|
|
|
87
86
|
/**
|
|
88
87
|
* 根据数组元素中的某一属性进行去重
|
|
89
88
|
* @param array
|
|
90
|
-
* @param
|
|
89
|
+
* @param value 获取元素唯一标识的函数
|
|
91
90
|
* @param override 遇到重复元素是否覆盖
|
|
92
91
|
*/
|
|
93
|
-
uniqueBy(array = [],
|
|
92
|
+
uniqueBy(array = [], value, override = false) {
|
|
93
|
+
array = array ?? [];
|
|
94
94
|
const map = new Map();
|
|
95
|
-
|
|
96
|
-
for (let i = 0; i < length; i++) {
|
|
95
|
+
for (let i = 0; i < array.length; i++) {
|
|
97
96
|
const e = array[i];
|
|
98
|
-
|
|
99
|
-
if (!override && map.has(key))
|
|
97
|
+
if (e == null)
|
|
100
98
|
continue;
|
|
101
|
-
|
|
99
|
+
const key = value(e);
|
|
100
|
+
if (!map.has(key) || override)
|
|
101
|
+
map.set(key, e);
|
|
102
102
|
}
|
|
103
103
|
return Array.from(map.values());
|
|
104
104
|
},
|