@ls-stack/utils 3.5.0 → 3.7.0
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/lib/arrayUtils.cjs +28 -0
- package/lib/arrayUtils.d.cts +3 -1
- package/lib/arrayUtils.d.ts +3 -1
- package/lib/arrayUtils.js +5 -1
- package/lib/{chunk-5JQGMNNY.js → chunk-XMUFRC2U.js} +27 -1
- package/lib/dedent.d.cts +2 -1
- package/lib/dedent.d.ts +2 -1
- package/lib/testUtils.js +1 -1
- package/package.json +1 -1
package/lib/arrayUtils.cjs
CHANGED
|
@@ -25,8 +25,10 @@ __export(arrayUtils_exports, {
|
|
|
25
25
|
filterAndMap: () => filterAndMap,
|
|
26
26
|
findAfterIndex: () => findAfterIndex,
|
|
27
27
|
findBeforeIndex: () => findBeforeIndex,
|
|
28
|
+
hasDuplicates: () => hasDuplicates,
|
|
28
29
|
isInArray: () => isInArray,
|
|
29
30
|
rejectArrayUndefinedValues: () => rejectArrayUndefinedValues,
|
|
31
|
+
rejectDuplicates: () => rejectDuplicates,
|
|
30
32
|
sortBy: () => sortBy
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(arrayUtils_exports);
|
|
@@ -107,6 +109,30 @@ function findBeforeIndex(array, index, predicate) {
|
|
|
107
109
|
function rejectArrayUndefinedValues(array) {
|
|
108
110
|
return array.filter((item) => item !== void 0);
|
|
109
111
|
}
|
|
112
|
+
function hasDuplicates(array, getKey = (item) => item) {
|
|
113
|
+
const seen = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const item of array) {
|
|
115
|
+
const key = getKey(item);
|
|
116
|
+
if (seen.has(key)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
seen.add(key);
|
|
120
|
+
}
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
function rejectDuplicates(array, getKey = (item) => item) {
|
|
124
|
+
const seen = /* @__PURE__ */ new Set();
|
|
125
|
+
const result = [];
|
|
126
|
+
for (const item of array) {
|
|
127
|
+
const key = getKey(item);
|
|
128
|
+
if (seen.has(key)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
seen.add(key);
|
|
132
|
+
result.push(item);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
110
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
137
|
0 && (module.exports = {
|
|
112
138
|
arrayWithPrev,
|
|
@@ -114,7 +140,9 @@ function rejectArrayUndefinedValues(array) {
|
|
|
114
140
|
filterAndMap,
|
|
115
141
|
findAfterIndex,
|
|
116
142
|
findBeforeIndex,
|
|
143
|
+
hasDuplicates,
|
|
117
144
|
isInArray,
|
|
118
145
|
rejectArrayUndefinedValues,
|
|
146
|
+
rejectDuplicates,
|
|
119
147
|
sortBy
|
|
120
148
|
});
|
package/lib/arrayUtils.d.cts
CHANGED
|
@@ -50,5 +50,7 @@ declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]):
|
|
|
50
50
|
declare function findAfterIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
51
51
|
declare function findBeforeIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
52
52
|
declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
53
|
+
declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
|
|
54
|
+
declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
|
|
53
55
|
|
|
54
|
-
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, isInArray, rejectArrayUndefinedValues, sortBy };
|
|
56
|
+
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy };
|
package/lib/arrayUtils.d.ts
CHANGED
|
@@ -50,5 +50,7 @@ declare function isInArray<T, const U extends T>(value: T, oneOf: readonly U[]):
|
|
|
50
50
|
declare function findAfterIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
51
51
|
declare function findBeforeIndex<T>(array: T[], index: number, predicate: (item: T) => boolean): T | undefined;
|
|
52
52
|
declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
53
|
+
declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
|
|
54
|
+
declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
|
|
53
55
|
|
|
54
|
-
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, isInArray, rejectArrayUndefinedValues, sortBy };
|
|
56
|
+
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy };
|
package/lib/arrayUtils.js
CHANGED
|
@@ -4,17 +4,21 @@ import {
|
|
|
4
4
|
filterAndMap,
|
|
5
5
|
findAfterIndex,
|
|
6
6
|
findBeforeIndex,
|
|
7
|
+
hasDuplicates,
|
|
7
8
|
isInArray,
|
|
8
9
|
rejectArrayUndefinedValues,
|
|
10
|
+
rejectDuplicates,
|
|
9
11
|
sortBy
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-XMUFRC2U.js";
|
|
11
13
|
export {
|
|
12
14
|
arrayWithPrev,
|
|
13
15
|
arrayWithPrevAndIndex,
|
|
14
16
|
filterAndMap,
|
|
15
17
|
findAfterIndex,
|
|
16
18
|
findBeforeIndex,
|
|
19
|
+
hasDuplicates,
|
|
17
20
|
isInArray,
|
|
18
21
|
rejectArrayUndefinedValues,
|
|
22
|
+
rejectDuplicates,
|
|
19
23
|
sortBy
|
|
20
24
|
};
|
|
@@ -76,6 +76,30 @@ function findBeforeIndex(array, index, predicate) {
|
|
|
76
76
|
function rejectArrayUndefinedValues(array) {
|
|
77
77
|
return array.filter((item) => item !== void 0);
|
|
78
78
|
}
|
|
79
|
+
function hasDuplicates(array, getKey = (item) => item) {
|
|
80
|
+
const seen = /* @__PURE__ */ new Set();
|
|
81
|
+
for (const item of array) {
|
|
82
|
+
const key = getKey(item);
|
|
83
|
+
if (seen.has(key)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
seen.add(key);
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
function rejectDuplicates(array, getKey = (item) => item) {
|
|
91
|
+
const seen = /* @__PURE__ */ new Set();
|
|
92
|
+
const result = [];
|
|
93
|
+
for (const item of array) {
|
|
94
|
+
const key = getKey(item);
|
|
95
|
+
if (seen.has(key)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
seen.add(key);
|
|
99
|
+
result.push(item);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
79
103
|
|
|
80
104
|
export {
|
|
81
105
|
filterAndMap,
|
|
@@ -85,5 +109,7 @@ export {
|
|
|
85
109
|
isInArray,
|
|
86
110
|
findAfterIndex,
|
|
87
111
|
findBeforeIndex,
|
|
88
|
-
rejectArrayUndefinedValues
|
|
112
|
+
rejectArrayUndefinedValues,
|
|
113
|
+
hasDuplicates,
|
|
114
|
+
rejectDuplicates
|
|
89
115
|
};
|
package/lib/dedent.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type InterpolateValue = string | number | boolean;
|
|
2
|
+
declare function dedent(strings: TemplateStringsArray, ...values: InterpolateValue[]): string;
|
|
2
3
|
declare function dedent(strings: string): string;
|
|
3
4
|
|
|
4
5
|
export { dedent };
|
package/lib/dedent.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
type InterpolateValue = string | number | boolean;
|
|
2
|
+
declare function dedent(strings: TemplateStringsArray, ...values: InterpolateValue[]): string;
|
|
2
3
|
declare function dedent(strings: string): string;
|
|
3
4
|
|
|
4
5
|
export { dedent };
|
package/lib/testUtils.js
CHANGED