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