@webdeveric/utils 0.79.0 → 0.80.1
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 +34 -12
- package/dist/mjs/unique.js +34 -12
- package/dist/types/unique.d.ts +7 -1
- package/package.json +17 -17
- package/dist/cjs/package.json +0 -1
- package/dist/mjs/package.json +0 -1
package/dist/cjs/unique.js
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.unique = unique;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const isAsyncIterable_js_1 = require("./predicate/isAsyncIterable.js");
|
|
5
|
+
const isIterable_js_1 = require("./predicate/isIterable.js");
|
|
6
|
+
function unique(items, options = {}) {
|
|
7
|
+
const ids = new Set();
|
|
8
|
+
const { filter, identity } = options;
|
|
9
|
+
if (typeof items === 'string' || (0, isIterable_js_1.isIterable)(items)) {
|
|
10
|
+
return {
|
|
11
|
+
*[Symbol.iterator]() {
|
|
12
|
+
for (const item of items) {
|
|
13
|
+
if (!filter || filter(item) === true) {
|
|
14
|
+
const id = identity?.(item) ?? item;
|
|
15
|
+
if (!ids.has(id)) {
|
|
16
|
+
ids.add(id);
|
|
17
|
+
yield item;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
7
23
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
if ((0, isAsyncIterable_js_1.isAsyncIterable)(items)) {
|
|
25
|
+
return {
|
|
26
|
+
async *[Symbol.asyncIterator]() {
|
|
27
|
+
for await (const item of items) {
|
|
28
|
+
if (!filter || filter(item) === true) {
|
|
29
|
+
const id = identity?.(item) ?? item;
|
|
30
|
+
if (!ids.has(id)) {
|
|
31
|
+
ids.add(id);
|
|
32
|
+
yield item;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
17
38
|
}
|
|
39
|
+
throw new TypeError('items must be an Iterable or AsyncIterable');
|
|
18
40
|
}
|
package/dist/mjs/unique.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { isAsyncIterable } from './predicate/isAsyncIterable.js';
|
|
2
|
+
import { isIterable } from './predicate/isIterable.js';
|
|
3
|
+
export function unique(items, options = {}) {
|
|
4
|
+
const ids = new Set();
|
|
5
|
+
const { filter, identity } = options;
|
|
6
|
+
if (typeof items === 'string' || isIterable(items)) {
|
|
7
|
+
return {
|
|
8
|
+
*[Symbol.iterator]() {
|
|
9
|
+
for (const item of items) {
|
|
10
|
+
if (!filter || filter(item) === true) {
|
|
11
|
+
const id = identity?.(item) ?? item;
|
|
12
|
+
if (!ids.has(id)) {
|
|
13
|
+
ids.add(id);
|
|
14
|
+
yield item;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
};
|
|
4
20
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
if (isAsyncIterable(items)) {
|
|
22
|
+
return {
|
|
23
|
+
async *[Symbol.asyncIterator]() {
|
|
24
|
+
for await (const item of items) {
|
|
25
|
+
if (!filter || filter(item) === true) {
|
|
26
|
+
const id = identity?.(item) ?? item;
|
|
27
|
+
if (!ids.has(id)) {
|
|
28
|
+
ids.add(id);
|
|
29
|
+
yield item;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
14
35
|
}
|
|
36
|
+
throw new TypeError('items must be an Iterable or AsyncIterable');
|
|
15
37
|
}
|
package/dist/types/unique.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type UniqueOptions<Type> = {
|
|
2
|
+
identity?: (item: Type) => unknown;
|
|
3
|
+
filter?: (item: Type) => boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function unique<Type>(items: AsyncIterable<Type>, options?: UniqueOptions<Type>): AsyncIterable<Type>;
|
|
6
|
+
export declare function unique<Type>(items: Iterable<Type>, options?: UniqueOptions<Type>): Iterable<Type>;
|
|
7
|
+
export declare function unique<Type>(items: AsyncIterable<Type> | Iterable<Type>, options?: UniqueOptions<Type>): AsyncIterable<Type> | Iterable<Type>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdeveric/utils",
|
|
3
3
|
"description": "Just another collection of utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.80.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"url": "https://github.com/webdeveric/utils/issues"
|
|
67
67
|
},
|
|
68
68
|
"homepage": "https://github.com/webdeveric/utils/#readme",
|
|
69
|
-
"packageManager": "pnpm@
|
|
69
|
+
"packageManager": "pnpm@11.8.0+sha512.c1f5e7c4cb241c8f174b743851d82f42b802324afc8b0f116b96adb15aa06664948dde36960a3ba1079ba5b4b29dd0140135b94b5b5f5263592249d68e555f26",
|
|
70
70
|
"scripts": {
|
|
71
|
-
"clean": "rimraf ./dist/",
|
|
71
|
+
"clean": "rimraf ./dist/ ./cache/ ./coverage/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
73
73
|
"build": "tsgo --build tsconfig.cjs.json tsconfig.mjs.json --force",
|
|
74
74
|
"postbuild": "echo '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && echo '{\"type\":\"module\"}' > ./dist/mjs/package.json && pnpm validate",
|
|
@@ -85,28 +85,28 @@
|
|
|
85
85
|
},
|
|
86
86
|
"prettier": "@webdeveric/prettier-config",
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"@commitlint/config-conventional": "^
|
|
89
|
-
"@commitlint/types": "^
|
|
90
|
-
"@types/node": "^24.
|
|
91
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
92
|
-
"@vitest/coverage-v8": "^4.1.
|
|
88
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
89
|
+
"@commitlint/types": "^21.0.1",
|
|
90
|
+
"@types/node": "^24.13.2",
|
|
91
|
+
"@typescript/native-preview": "7.0.0-dev.20260617.2",
|
|
92
|
+
"@vitest/coverage-v8": "^4.1.9",
|
|
93
93
|
"@webdeveric/eslint-config-ts": "^0.12.0",
|
|
94
94
|
"@webdeveric/prettier-config": "^0.4.0",
|
|
95
|
-
"commitlint": "^
|
|
96
|
-
"commitlint-plugin-cspell": "^0.
|
|
95
|
+
"commitlint": "^21.0.2",
|
|
96
|
+
"commitlint-plugin-cspell": "^0.9.2",
|
|
97
97
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
98
|
-
"cspell": "^10.0.
|
|
98
|
+
"cspell": "^10.0.1",
|
|
99
99
|
"eslint": "^8.57.1",
|
|
100
100
|
"eslint-config-prettier": "^10.1.8",
|
|
101
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
101
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
102
102
|
"eslint-plugin-import": "^2.32.0",
|
|
103
103
|
"husky": "^9.1.7",
|
|
104
104
|
"jsdom": "^29.1.1",
|
|
105
|
-
"lint-staged": "^
|
|
106
|
-
"prettier": "^3.8.
|
|
105
|
+
"lint-staged": "^17.0.7",
|
|
106
|
+
"prettier": "^3.8.4",
|
|
107
107
|
"rimraf": "^6.1.3",
|
|
108
|
-
"semantic-release": "^25.0.
|
|
109
|
-
"validate-package-exports": "^
|
|
110
|
-
"vitest": "^4.1.
|
|
108
|
+
"semantic-release": "^25.0.5",
|
|
109
|
+
"validate-package-exports": "^1.1.0",
|
|
110
|
+
"vitest": "^4.1.9"
|
|
111
111
|
}
|
|
112
112
|
}
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/dist/mjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|