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