Skip to content

Commit 304721c

Browse files
authored
Merge pull request #191 from webdeveric/dev
Added `NonEmptyArray` utility type
2 parents 68091a2 + ee4a3fc commit 304721c

9 files changed

Lines changed: 356 additions & 283 deletions

File tree

bench/convert.bench.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { bench } from 'vitest';
2+
3+
import { convert, type ConvertRecord } from '../src/convert.js';
4+
5+
const input = {
6+
firstName: 'Test',
7+
lastName: 'Testerson',
8+
age: 42,
9+
};
10+
11+
const converter: ConvertRecord<typeof input, { fullName: string; age: number }> = {
12+
fullName: (data) => data.firstName + ' ' + data.lastName,
13+
age: (data) => data.age,
14+
};
15+
16+
bench('convert()', () => {
17+
convert(input, converter);
18+
});

bench/getOwnProperties.bench.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { bench } from 'vitest';
2+
3+
import { getOwnProperties } from '../src/getOwnProperties.js';
4+
5+
bench('getOwnProperties()', () => {
6+
getOwnProperties(globalThis);
7+
});

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"url": "https://github.com/webdeveric/utils/issues"
6767
},
6868
"homepage": "https://github.com/webdeveric/utils/#readme",
69-
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977",
69+
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
7070
"scripts": {
7171
"clean": "rimraf ./dist/",
7272
"prebuild": "pnpm clean",
@@ -87,8 +87,8 @@
8787
"devDependencies": {
8888
"@commitlint/config-conventional": "^19.8.1",
8989
"@commitlint/types": "^19.8.1",
90-
"@types/node": "^22.15.29",
91-
"@vitest/coverage-v8": "^3.1.4",
90+
"@types/node": "^22.15.30",
91+
"@vitest/coverage-v8": "^3.2.2",
9292
"@webdeveric/eslint-config-ts": "^0.11.0",
9393
"@webdeveric/prettier-config": "^0.3.0",
9494
"commitlint": "^19.8.1",
@@ -97,7 +97,7 @@
9797
"cspell": "^9.0.2",
9898
"eslint": "^8.57.1",
9999
"eslint-config-prettier": "^10.1.5",
100-
"eslint-import-resolver-typescript": "^4.4.2",
100+
"eslint-import-resolver-typescript": "^4.4.3",
101101
"eslint-plugin-import": "^2.31.0",
102102
"husky": "^9.1.7",
103103
"jsdom": "^26.1.0",
@@ -107,7 +107,7 @@
107107
"semantic-release": "^24.2.5",
108108
"typescript": "^5.8.3",
109109
"validate-package-exports": "^0.9.0",
110-
"vitest": "^3.1.4"
110+
"vitest": "^3.2.2"
111111
},
112112
"pnpm": {
113113
"onlyBuiltDependencies": [

pnpm-lock.yaml

Lines changed: 312 additions & 274 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/predicate/factory/allOf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { NonEmptyArray } from '../../types/arrays.js';
12
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
23
import type { IntersectionOf } from '../../types/utils.js';
34

45
/**
56
* All predicates must pass
67
*/
7-
export const allOf = <Predicates extends TypePredicateFn<unknown>[]>(
8+
export const allOf = <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(
89
...predicates: Predicates
910
): TypePredicateFn<IntersectionOf<InferPredicatesReturnType<Predicates>>> => {
1011
if (!predicates.length) {

src/predicate/factory/anyOf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { NonEmptyArray } from '../../types/arrays.js';
12
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
23
import type { UnionOf } from '../../types/utils.js';
34

45
/**
56
* Any predicate can pass
67
*/
7-
export const anyOf = <Predicates extends TypePredicateFn<unknown>[]>(
8+
export const anyOf = <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(
89
...predicates: Predicates
910
): TypePredicateFn<UnionOf<InferPredicatesReturnType<Predicates>>> => {
1011
if (!predicates.length) {

src/types/arrays.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ export type IfLength<A extends any[], L extends number, T, F> = GetLength<A> ext
1414
export type IfEmpty<A extends any[], T, F> = GetLength<A> extends 0 ? T : F;
1515

1616
export type IfArray<Type, T, F> = Type extends unknown[] ? T : F;
17+
18+
export type NonEmptyArray<Type> = [Type, ...Type[]];

test/predicate/factory/allOf.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { isString } from '../../../src/predicate/isString.js';
77

88
describe('allOf()', () => {
99
it('Requires one or more type predicate function', () => {
10-
expect(() => allOf()).toThrow();
10+
expect(() => {
11+
// @ts-expect-error testing missing arguments
12+
allOf();
13+
}).toThrow();
1114
});
1215

1316
it('Returns a type predicate function', () => {

test/predicate/factory/anyOf.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { anyOf } from '../../../src/predicate/factory/anyOf.js';
44

55
describe('anyOf()', () => {
66
it('Requires one or more type predicate function', () => {
7-
expect(() => anyOf()).toThrow();
7+
expect(() => {
8+
// @ts-expect-error testing missing arguments
9+
return anyOf();
10+
}).toThrow();
811
});
912

1013
it('Returns a type predicate function', () => {

0 commit comments

Comments
 (0)