zek 19.0.12 → 19.0.14
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/fesm2022/zek.mjs +23 -1
- package/fesm2022/zek.mjs.map +1 -1
- package/lib/utils/array-helper.d.ts +6 -0
- package/package.json +1 -1
package/fesm2022/zek.mjs
CHANGED
|
@@ -92,6 +92,28 @@ class ArrayHelper {
|
|
|
92
92
|
}
|
|
93
93
|
return result;
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns a new array with duplicates removed based on a specific key or selector.
|
|
97
|
+
* @param array The source array.
|
|
98
|
+
* @param keySelector A function that returns the value to compare by.
|
|
99
|
+
*/
|
|
100
|
+
static distinctBy(array, keySelector) {
|
|
101
|
+
// Guard clause for null/undefined or empty arrays
|
|
102
|
+
if (!array || array.length === 0) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
const result = [];
|
|
107
|
+
// Using a for...of loop is often cleaner than standard for loop in modern JS
|
|
108
|
+
for (const item of array) {
|
|
109
|
+
const key = keySelector(item);
|
|
110
|
+
if (!seen.has(key)) {
|
|
111
|
+
seen.add(key);
|
|
112
|
+
result.push(item);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
95
117
|
static filterByKey(filterValue, key, array) {
|
|
96
118
|
if (typeof filterValue === 'undefined' || filterValue == null || (typeof key === 'string' && key.length === 0))
|
|
97
119
|
return array;
|
|
@@ -1523,7 +1545,7 @@ class UrlHelper {
|
|
|
1523
1545
|
static combine(...parts) {
|
|
1524
1546
|
let result = '';
|
|
1525
1547
|
for (const part of parts) {
|
|
1526
|
-
if (typeof part === 'undefined'
|
|
1548
|
+
if (typeof part === 'undefined' || part === null)
|
|
1527
1549
|
continue;
|
|
1528
1550
|
const str = `${part}`;
|
|
1529
1551
|
result = this.combineEnsureSingleSeparator(result, str, '/');
|