Skip to content

Commit 1d7c1ab

Browse files
authored
Merge pull request #182 from webdeveric/dev
Miscellaneous updates
2 parents a57654b + b1075a3 commit 1d7c1ab

15 files changed

Lines changed: 240 additions & 262 deletions

bench/isPrimitive.bench.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { bench } from 'vitest';
2+
3+
import { isPrimitive } from '../src/predicate/isPrimitive.js';
4+
5+
import type { Primitive } from '../src/index.js';
6+
7+
const data: Primitive[] = ['string', 1, 1n, true, undefined, Symbol('test'), null];
8+
9+
bench('isPrimitive()', () => {
10+
data.forEach(isPrimitive);
11+
});

bench/isPromiseLike.bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isObjectWith } from '../src/predicate/isObjectWith.js';
55
import { isPromiseLike } from '../src/predicate/isPromiseLike.js';
66

77
function isPromiseLike2<T>(input: unknown): input is PromiseLike<T> {
8-
return isObjectWith(input, 'then') && isFunction(input.then) && input.then.length === 2;
8+
return isObjectWith(input, ['then']) && isFunction(input.then) && input.then.length === 2;
99
}
1010

1111
const resolvedPromise = Promise.resolve();

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"devDependencies": {
8888
"@commitlint/config-conventional": "^19.8.0",
8989
"@commitlint/types": "^19.8.0",
90-
"@types/node": "^22.13.11",
90+
"@types/node": "^22.13.13",
9191
"@vitest/coverage-v8": "^3.0.9",
9292
"@webdeveric/eslint-config-ts": "^0.11.0",
9393
"@webdeveric/prettier-config": "^0.3.0",
@@ -106,7 +106,7 @@
106106
"rimraf": "^6.0.1",
107107
"semantic-release": "^24.2.3",
108108
"typescript": "^5.8.2",
109-
"validate-package-exports": "^0.8.0",
109+
"validate-package-exports": "^0.9.0",
110110
"vitest": "^3.0.9"
111111
},
112112
"pnpm": {

pnpm-lock.yaml

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

src/assertion/assertIsObject.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { isObject } from '../predicate/isObject.js';
22

33
import { getError } from './getError.js';
44

5+
import type { UnknownRecord } from '../types/records.js';
6+
57
export function assertIsObject(
68
input: unknown,
79
error: string | Error = 'input is not an object',
8-
): asserts input is object {
10+
): asserts input is UnknownRecord {
911
if (!isObject(input)) {
1012
throw getError(error);
1113
}

src/predicate/isAnyObjectWith.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { asArray } from '../asArray.js';
2-
31
import { isAnyObject } from './isAnyObject.js';
42

53
/**
64
* Determine if `input` is an object and has the provided properties.
75
*/
86
export const isAnyObjectWith = <T, P extends PropertyKey>(
97
input: T,
10-
properties: P | P[],
8+
properties: P[],
119
): input is T & Record<P, unknown> => {
12-
return isAnyObject(input) && asArray(properties).every((property) => property in input);
10+
return isAnyObject(input) && properties.every((property) => property in input);
1311
};
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { asArray } from '../asArray.js';
2-
31
import { isAnyObject } from './isAnyObject.js';
42

53
/**
64
* Determine if `input` is an object and directly has the provided properties.
75
*/
86
export const isAnyObjectWithOwn = <T, P extends PropertyKey>(
97
input: T,
10-
properties: P | P[],
8+
properties: P[],
119
): input is T & Record<P, unknown> => {
12-
return isAnyObject(input) && asArray(properties).every((property) => Object.hasOwn(input, property));
10+
return isAnyObject(input) && properties.every((property) => Object.hasOwn(input, property));
1311
};

src/predicate/isObject.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import type { UnknownRecord } from '../types/records.js';
2+
13
/**
24
* Determine if `input` is a non-null object and not an array.
35
*/
4-
export const isObject = (input: unknown): input is object =>
6+
export const isObject = (input: unknown): input is UnknownRecord =>
57
input !== null && typeof input === 'object' && !Array.isArray(input);

src/predicate/isObjectWith.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import { asArray } from '../asArray.js';
2-
31
import { isObject } from './isObject.js';
42

53
/**
64
* Determine if `input` is an object and has the provided properties.
75
*/
8-
export const isObjectWith = <T, P extends PropertyKey>(
9-
input: T,
10-
properties: P | P[],
11-
): input is T & Record<P, unknown> => {
12-
return isObject(input) && asArray(properties).every((property) => property in input);
13-
};
6+
export const isObjectWith = <T, P extends PropertyKey>(input: T, properties: P[]): input is T & Record<P, unknown> =>
7+
isObject(input) && properties.every((property) => property in input);

src/predicate/isPrimitive.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
import { isBigInt } from './isBigInt.js';
2-
import { isBoolean } from './isBoolean.js';
3-
import { isNull } from './isNull.js';
4-
import { isNumber } from './isNumber.js';
5-
import { isString } from './isString.js';
6-
import { isSymbol } from './isSymbol.js';
7-
import { isUndefined } from './isUndefined.js';
8-
91
import type { Primitive } from '../types/common.js';
102

113
export const isPrimitive = (input: unknown): input is Primitive =>
12-
isString(input) ||
13-
isNumber(input) ||
14-
isBigInt(input) ||
15-
isBoolean(input) ||
16-
isUndefined(input) ||
17-
isSymbol(input) ||
18-
isNull(input);
4+
input === null ||
5+
typeof input === 'string' ||
6+
typeof input === 'number' ||
7+
typeof input === 'bigint' ||
8+
typeof input === 'boolean' ||
9+
typeof input === 'undefined' ||
10+
typeof input === 'symbol';

0 commit comments

Comments
 (0)