@webdeveric/utils 0.82.0 → 0.83.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/predicate/factory/is.js +6 -1
- package/dist/cjs/unique.js +5 -6
- package/dist/mjs/predicate/factory/is.js +6 -1
- package/dist/mjs/unique.js +5 -6
- package/dist/types/predicate/factory/is.d.ts +3 -1
- package/dist/types/types/numbers.d.ts +3 -1
- package/dist/types/unique.d.ts +5 -0
- package/package.json +13 -12
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.is = void 0;
|
|
4
|
-
const is = (...values) =>
|
|
4
|
+
const is = (...values) => {
|
|
5
|
+
if (!values.length) {
|
|
6
|
+
throw new Error('Values not provided');
|
|
7
|
+
}
|
|
8
|
+
return (input) => values.some((value) => Object.is(input, value));
|
|
9
|
+
};
|
|
5
10
|
exports.is = is;
|
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
|
}
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export const is = (...values) =>
|
|
1
|
+
export const is = (...values) => {
|
|
2
|
+
if (!values.length) {
|
|
3
|
+
throw new Error('Values not provided');
|
|
4
|
+
}
|
|
5
|
+
return (input) => values.some((value) => Object.is(input, value));
|
|
6
|
+
};
|
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
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import type { NonEmptyArray } from '../../types/arrays.js';
|
|
1
2
|
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
|
-
|
|
3
|
+
import type { UnionOf } from '../../types/utils.js';
|
|
4
|
+
export declare const is: <const Values extends NonEmptyArray<unknown>>(...values: Values) => TypePredicateFn<UnionOf<Values>>;
|
|
@@ -7,4 +7,6 @@ export type BinaryNumberString = `0${'b' | 'B'}${number}`;
|
|
|
7
7
|
export type ExponentiationString = `${number}${'e' | 'E'}${number}`;
|
|
8
8
|
export type Int32 = Branded<number, 'Int32'>;
|
|
9
9
|
export type UInt32 = Branded<number, 'UInt32'>;
|
|
10
|
-
export type NumberRange = [
|
|
10
|
+
export type NumberRange = [
|
|
11
|
+
min: number
|
|
12
|
+
] | [min: number, max: undefined] | [min: number, max: number] | [min: undefined, max: number];
|
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>;
|
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.83.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"url": "https://github.com/webdeveric/utils/issues"
|
|
67
67
|
},
|
|
68
68
|
"homepage": "https://github.com/webdeveric/utils/#readme",
|
|
69
|
-
"packageManager": "pnpm@11.
|
|
69
|
+
"packageManager": "pnpm@11.11.0+sha512.4463f65fd80ed80d69bc1d4bf163ee94f605c7380fc318bb5b2ebe15f8cd12d49c51a4d59e951b401e764d3b6ca751cbf51bc50ed7001a6bcb4935e684c34882",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/ ./cache/ ./coverage/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -85,14 +85,15 @@
|
|
|
85
85
|
},
|
|
86
86
|
"prettier": "@webdeveric/prettier-config",
|
|
87
87
|
"devDependencies": {
|
|
88
|
-
"@commitlint/config-conventional": "^21.
|
|
89
|
-
"@commitlint/types": "^21.
|
|
90
|
-
"@types/node": "^24.13.
|
|
91
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
92
|
-
"@vitest/coverage-v8": "^4.1.
|
|
93
|
-
"@webdeveric/eslint-config-ts": "^0.12.
|
|
88
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
89
|
+
"@commitlint/types": "^21.2.0",
|
|
90
|
+
"@types/node": "^24.13.3",
|
|
91
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
92
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
93
|
+
"@webdeveric/eslint-config-ts": "^0.12.1",
|
|
94
94
|
"@webdeveric/prettier-config": "^0.4.0",
|
|
95
|
-
"
|
|
95
|
+
"@webdeveric/ts-data-structures": "^1.0.1",
|
|
96
|
+
"commitlint": "^21.2.1",
|
|
96
97
|
"commitlint-plugin-cspell": "^0.9.3",
|
|
97
98
|
"conventional-changelog-conventionalcommits": "^9.3.1",
|
|
98
99
|
"cspell": "^10.0.1",
|
|
@@ -103,10 +104,10 @@
|
|
|
103
104
|
"husky": "^9.1.7",
|
|
104
105
|
"jsdom": "^29.1.1",
|
|
105
106
|
"lint-staged": "^17.0.8",
|
|
106
|
-
"prettier": "^3.9.
|
|
107
|
+
"prettier": "^3.9.4",
|
|
107
108
|
"rimraf": "^6.1.3",
|
|
108
109
|
"semantic-release": "^25.0.5",
|
|
109
|
-
"validate-package-exports": "^1.
|
|
110
|
-
"vitest": "^4.1.
|
|
110
|
+
"validate-package-exports": "^1.2.1",
|
|
111
|
+
"vitest": "^4.1.10"
|
|
111
112
|
}
|
|
112
113
|
}
|