@whitesev/utils 2.3.1 → 2.3.2
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 +21 -5
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +21 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +21 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +21 -5
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +21 -5
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +21 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +9 -0
- package/package.json +1 -1
- package/src/Utils.ts +38 -10
package/dist/index.esm.js
CHANGED
|
@@ -6439,13 +6439,29 @@ class Utils {
|
|
|
6439
6439
|
* > ()=>{throw new Error('测试错误')}出现错误
|
|
6440
6440
|
*/
|
|
6441
6441
|
tryCatch = TryCatch;
|
|
6442
|
-
uniqueArray(uniqueArrayData = [], compareArrayData
|
|
6443
|
-
// @ts-ignore
|
|
6442
|
+
uniqueArray(uniqueArrayData = [], compareArrayData, compareFun = (item, item2) => {
|
|
6444
6443
|
return item === item2;
|
|
6445
6444
|
}) {
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6445
|
+
if (typeof compareArrayData === "function") {
|
|
6446
|
+
const compareFn = compareArrayData;
|
|
6447
|
+
const seen = new Set();
|
|
6448
|
+
const result = [];
|
|
6449
|
+
for (const item of uniqueArrayData) {
|
|
6450
|
+
// 使用compareFn函数来获取当前对象的唯一标识
|
|
6451
|
+
const identfier = compareFn(item);
|
|
6452
|
+
// 如果Set中还没有这个标识,则添加到结果数组中,并将其标识存入Set
|
|
6453
|
+
if (!seen.has(identfier)) {
|
|
6454
|
+
seen.add(identfier);
|
|
6455
|
+
result.push(item);
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
return result;
|
|
6459
|
+
}
|
|
6460
|
+
else {
|
|
6461
|
+
return Array.from(uniqueArrayData).filter((item) => !Array.from(compareArrayData).some(function (item2) {
|
|
6462
|
+
return compareFun(item, item2);
|
|
6463
|
+
}));
|
|
6464
|
+
}
|
|
6449
6465
|
}
|
|
6450
6466
|
waitArrayLoopToEnd(data, handleFunc) {
|
|
6451
6467
|
let UtilsContext = this;
|