@webdeveric/utils 0.82.0 → 0.83.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/dist/cjs/unique.js +5 -6
- package/dist/mjs/unique.js +5 -6
- package/dist/types/unique.d.ts +5 -0
- package/package.json +1 -1
package/dist/cjs/unique.js
CHANGED
|
@@ -4,16 +4,15 @@ exports.unique = unique;
|
|
|
4
4
|
const isAsyncIterable_js_1 = require("./predicate/isAsyncIterable.js");
|
|
5
5
|
const isIterable_js_1 = require("./predicate/isIterable.js");
|
|
6
6
|
function unique(items, options = {}) {
|
|
7
|
-
const
|
|
8
|
-
const { filter, identity } = options;
|
|
7
|
+
const { filter, identity, store = new Set() } = options;
|
|
9
8
|
if (typeof items === 'string' || (0, isIterable_js_1.isIterable)(items)) {
|
|
10
9
|
return {
|
|
11
10
|
*[Symbol.iterator]() {
|
|
12
11
|
for (const item of items) {
|
|
13
12
|
if (!filter || filter(item) === true) {
|
|
14
13
|
const id = identity?.(item) ?? item;
|
|
15
|
-
if (!
|
|
16
|
-
|
|
14
|
+
if (!store.has(id)) {
|
|
15
|
+
store.add(id);
|
|
17
16
|
yield item;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
@@ -27,8 +26,8 @@ function unique(items, options = {}) {
|
|
|
27
26
|
for await (const item of items) {
|
|
28
27
|
if (!filter || filter(item) === true) {
|
|
29
28
|
const id = identity?.(item) ?? item;
|
|
30
|
-
if (!
|
|
31
|
-
|
|
29
|
+
if (!store.has(id)) {
|
|
30
|
+
store.add(id);
|
|
32
31
|
yield item;
|
|
33
32
|
}
|
|
34
33
|
}
|
package/dist/mjs/unique.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { isAsyncIterable } from './predicate/isAsyncIterable.js';
|
|
2
2
|
import { isIterable } from './predicate/isIterable.js';
|
|
3
3
|
export function unique(items, options = {}) {
|
|
4
|
-
const
|
|
5
|
-
const { filter, identity } = options;
|
|
4
|
+
const { filter, identity, store = new Set() } = options;
|
|
6
5
|
if (typeof items === 'string' || isIterable(items)) {
|
|
7
6
|
return {
|
|
8
7
|
*[Symbol.iterator]() {
|
|
9
8
|
for (const item of items) {
|
|
10
9
|
if (!filter || filter(item) === true) {
|
|
11
10
|
const id = identity?.(item) ?? item;
|
|
12
|
-
if (!
|
|
13
|
-
|
|
11
|
+
if (!store.has(id)) {
|
|
12
|
+
store.add(id);
|
|
14
13
|
yield item;
|
|
15
14
|
}
|
|
16
15
|
}
|
|
@@ -24,8 +23,8 @@ export function unique(items, options = {}) {
|
|
|
24
23
|
for await (const item of items) {
|
|
25
24
|
if (!filter || filter(item) === true) {
|
|
26
25
|
const id = identity?.(item) ?? item;
|
|
27
|
-
if (!
|
|
28
|
-
|
|
26
|
+
if (!store.has(id)) {
|
|
27
|
+
store.add(id);
|
|
29
28
|
yield item;
|
|
30
29
|
}
|
|
31
30
|
}
|
package/dist/types/unique.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
export type MembershipStore<T> = {
|
|
2
|
+
has(value: T): boolean;
|
|
3
|
+
add(value: T): void;
|
|
4
|
+
};
|
|
1
5
|
export type UniqueOptions<Type> = {
|
|
2
6
|
identity?: (item: Type) => unknown;
|
|
3
7
|
filter?: (item: Type) => boolean;
|
|
8
|
+
store?: MembershipStore<unknown>;
|
|
4
9
|
};
|
|
5
10
|
export declare function unique<Type>(items: AsyncIterable<Type>, options?: UniqueOptions<Type>): AsyncIterable<Type>;
|
|
6
11
|
export declare function unique<Type>(items: Iterable<Type>, options?: UniqueOptions<Type>): Iterable<Type>;
|