Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bench/convert.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { bench } from 'vitest';

import { convert, type ConvertRecord } from '../src/convert.js';

const input = {
firstName: 'Test',
lastName: 'Testerson',
age: 42,
};

const converter: ConvertRecord<typeof input, { fullName: string; age: number }> = {
fullName: (data) => data.firstName + ' ' + data.lastName,
age: (data) => data.age,
};

bench('convert()', () => {
convert(input, converter);
});
7 changes: 7 additions & 0 deletions bench/getOwnProperties.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { bench } from 'vitest';

import { getOwnProperties } from '../src/getOwnProperties.js';

bench('getOwnProperties()', () => {
getOwnProperties(globalThis);
});
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"url": "https://github.com/webdeveric/utils/issues"
},
"homepage": "https://github.com/webdeveric/utils/#readme",
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977",
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
"scripts": {
"clean": "rimraf ./dist/",
"prebuild": "pnpm clean",
Expand All @@ -87,8 +87,8 @@
"devDependencies": {
"@commitlint/config-conventional": "^19.8.1",
"@commitlint/types": "^19.8.1",
"@types/node": "^22.15.29",
"@vitest/coverage-v8": "^3.1.4",
"@types/node": "^22.15.30",
"@vitest/coverage-v8": "^3.2.2",
"@webdeveric/eslint-config-ts": "^0.11.0",
"@webdeveric/prettier-config": "^0.3.0",
"commitlint": "^19.8.1",
Expand All @@ -97,7 +97,7 @@
"cspell": "^9.0.2",
"eslint": "^8.57.1",
"eslint-config-prettier": "^10.1.5",
"eslint-import-resolver-typescript": "^4.4.2",
"eslint-import-resolver-typescript": "^4.4.3",
"eslint-plugin-import": "^2.31.0",
"husky": "^9.1.7",
"jsdom": "^26.1.0",
Expand All @@ -107,7 +107,7 @@
"semantic-release": "^24.2.5",
"typescript": "^5.8.3",
"validate-package-exports": "^0.9.0",
"vitest": "^3.1.4"
"vitest": "^3.2.2"
},
"pnpm": {
"onlyBuiltDependencies": [
Expand Down
586 changes: 312 additions & 274 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/predicate/factory/allOf.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { NonEmptyArray } from '../../types/arrays.js';
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
import type { IntersectionOf } from '../../types/utils.js';

/**
* All predicates must pass
*/
export const allOf = <Predicates extends TypePredicateFn<unknown>[]>(
export const allOf = <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(
...predicates: Predicates
): TypePredicateFn<IntersectionOf<InferPredicatesReturnType<Predicates>>> => {
if (!predicates.length) {
Expand Down
3 changes: 2 additions & 1 deletion src/predicate/factory/anyOf.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { NonEmptyArray } from '../../types/arrays.js';
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
import type { UnionOf } from '../../types/utils.js';

/**
* Any predicate can pass
*/
export const anyOf = <Predicates extends TypePredicateFn<unknown>[]>(
export const anyOf = <Predicates extends NonEmptyArray<TypePredicateFn<unknown>>>(
...predicates: Predicates
): TypePredicateFn<UnionOf<InferPredicatesReturnType<Predicates>>> => {
if (!predicates.length) {
Expand Down
2 changes: 2 additions & 0 deletions src/types/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export type IfLength<A extends any[], L extends number, T, F> = GetLength<A> ext
export type IfEmpty<A extends any[], T, F> = GetLength<A> extends 0 ? T : F;

export type IfArray<Type, T, F> = Type extends unknown[] ? T : F;

export type NonEmptyArray<Type> = [Type, ...Type[]];
5 changes: 4 additions & 1 deletion test/predicate/factory/allOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { isString } from '../../../src/predicate/isString.js';

describe('allOf()', () => {
it('Requires one or more type predicate function', () => {
expect(() => allOf()).toThrow();
expect(() => {
// @ts-expect-error testing missing arguments
allOf();
}).toThrow();
});

it('Returns a type predicate function', () => {
Expand Down
5 changes: 4 additions & 1 deletion test/predicate/factory/anyOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { anyOf } from '../../../src/predicate/factory/anyOf.js';

describe('anyOf()', () => {
it('Requires one or more type predicate function', () => {
expect(() => anyOf()).toThrow();
expect(() => {
// @ts-expect-error testing missing arguments
return anyOf();
}).toThrow();
});

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