Skip to content
Merged

Dev #153

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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@
},
"prettier": "@webdeveric/prettier-config",
"devDependencies": {
"@types/node": "^22.9.1",
"@vitest/coverage-v8": "^2.1.5",
"@types/node": "^22.10.1",
"@vitest/coverage-v8": "^2.1.6",
"@webdeveric/eslint-config-ts": "^0.11.0",
"@webdeveric/prettier-config": "^0.3.0",
"cspell": "^8.16.0",
"cspell": "^8.16.1",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"husky": "^9.1.7",
"jsdom": "^25.0.1",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"prettier": "^3.4.1",
"rimraf": "^6.0.1",
"typescript": "^5.7.2",
"validate-package-exports": "^0.7.0",
"vitest": "^2.1.5"
"vitest": "^2.1.6"
}
}
916 changes: 472 additions & 444 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/describeInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const describeInput = (input: unknown): string => {
case 'symbol':
return input.toString();
case 'function': {
const args = input.toString().match(/^(function\s*\w*)?(?<args>\([^)]*\))/)?.groups?.args;
const args = /^(function\s*\w*)?(?<args>\([^)]*\))/.exec(input.toString())?.groups?.['args'];

return `${input.name || 'anonymous'}${args}`;
}
Expand All @@ -18,7 +18,7 @@ export const describeInput = (input: unknown): string => {
return 'Numeric String';
}

const authType = input.match(/^(?<authType>Basic|Bearer)\s.+/i)?.groups?.authType;
const authType = /^(?<authType>Basic|Bearer)\s.+/i.exec(input)?.groups?.['authType'];

if (authType) {
return `${authType} Authorization`;
Expand Down
2 changes: 1 addition & 1 deletion src/getPackageName.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function getPackageName(input: string): string | undefined {
return input.match(/^(?<pkg>(?:(?<scope>@[^/]+)\/)?(?<name>[a-z][^/]+))/i)?.groups?.pkg;
return /^(?<pkg>(?:(?<scope>@[^/]+)\/)?(?<name>[a-z][^/]+))/i.exec(input)?.groups?.['pkg'];
}
2 changes: 2 additions & 0 deletions src/predicate/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './isAnyObject.js';
export * from './isAnyObjectWith.js';
export * from './isAsyncIterable.js';
export * from './isBigInt.js';
export * from './isBigIntArray.js';
Expand Down
6 changes: 6 additions & 0 deletions src/predicate/isAnyObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { UnknownRecord } from '../types/records.js';

/**
* Determine if `input` is any non-null object.
*/
export const isAnyObject = <T>(input: T): input is T & UnknownRecord => input !== null && typeof input === 'object';
13 changes: 13 additions & 0 deletions src/predicate/isAnyObjectWith.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { asArray } from '../asArray.js';

import { isAnyObject } from './isAnyObject.js';

/**
* Determine if `input` is an object and has the provided properties.
*/
export const isAnyObjectWith = <T, P extends PropertyKey>(
input: T,
properties: P | P[],
): input is T & Record<P, unknown> => {
return isAnyObject(input) && asArray(properties).every((property) => property in input);
};
6 changes: 4 additions & 2 deletions src/predicate/isObject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { UnknownRecord } from '../types/records.js';

/**
* Determine if `input` is an object and not null or an array.
* Determine if `input` is a non-null object and not an array.
*/
export const isObject = (input: unknown): input is object =>
export const isObject = <T>(input: T): input is T & UnknownRecord =>
input !== null && typeof input === 'object' && !Array.isArray(input);
5 changes: 3 additions & 2 deletions src/trimIndentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const isWhitespaceOnly = (input: string): boolean => /^\s*$/.test(input);

export function trimIndentation(input: string): string {
const lines = input.split('\n');
const firstNonWhitespaceLine = lines.find((line) => !isWhitespaceOnly(line));
const whiteSpace = firstNonWhitespaceLine?.match(/^(?<whiteSpace>\s*)/)?.groups?.whiteSpace;
const whiteSpace = lines.find((line) => !isWhitespaceOnly(line))?.match(/^(?<whiteSpace>\s*)/)?.groups?.[
'whiteSpace'
];

if (whiteSpace) {
const wsPattern = new RegExp(`^${whiteSpace}`);
Expand Down
13 changes: 13 additions & 0 deletions test/predicate/isAnyObject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, it, expect } from 'vitest';

import { isAnyObject } from '../../src/predicate/isAnyObject.js';

describe('isAnyObject()', () => {
it.each([{}, [], new Object(), new Date()])('Returns true for valid inputs', (item) => {
expect(isAnyObject(item)).toBeTruthy();
});

it.each([null, false, 'string', Math.PI, Symbol(), undefined])('Returns false for invalid inputs', (item) => {
expect(isAnyObject(item)).toBeFalsy();
});
});
16 changes: 16 additions & 0 deletions test/predicate/isAnyObjectWith.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, it, expect } from 'vitest';

import { isAnyObjectWith } from '../../src/predicate/isAnyObjectWith.js';

describe('isAnyObjectWith()', () => {
it('Returns true for valid inputs', () => {
expect(isAnyObjectWith({ property: true }, 'property')).toBeTruthy();
expect(isAnyObjectWith({ name: 'Test Testerson', age: 100 }, ['name', 'age'])).toBeTruthy();
expect(isAnyObjectWith(['item'], 'length')).toBeTruthy();
});

it.each([null, false, 'string', Math.PI, Symbol()])('Returns false for invalid inputs', (item) => {
expect(isAnyObjectWith(item, 'property')).toBeFalsy();
expect(isAnyObjectWith(item, ['property'])).toBeFalsy();
});
});
13 changes: 13 additions & 0 deletions test/predicate/isObject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, it, expect } from 'vitest';

import { isObject } from '../../src/predicate/isObject.js';

describe('isObject()', () => {
it.each([{}, new Object(), new Date()])('Returns true for valid inputs', (item) => {
expect(isObject(item)).toBeTruthy();
});

it.each([null, false, 'string', Math.PI, Symbol(), undefined, []])('Returns false for invalid inputs', (item) => {
expect(isObject(item)).toBeFalsy();
});
});
12 changes: 0 additions & 12 deletions test/type-predicate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
isNumericString,
isNumericValue,
isNumericValueArray,
isObject,
isOptionalBigInt,
isOptionalBoolean,
isOptionalISODateString,
Expand Down Expand Up @@ -466,17 +465,6 @@ describe('isAsyncIterable()', () => {
});
});

describe('isObject()', () => {
it('Returns true for valid inputs', () => {
expect(isObject({})).toBeTruthy();
});

it('Returns false for invalid inputs', () => {
expect(isObject('test')).toBeFalsy();
expect(isObject(null)).toBeFalsy();
});
});

describe('isLengthAware()', () => {
it('Returns true for valid inputs', () => {
expect(isLengthAware([])).toBeTruthy();
Expand Down
4 changes: 2 additions & 2 deletions test/until.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ describe('until()', () => {
it('Keeps track of arbitrary data', async () => {
const result = await until<UntilContext>(
(resolve, _reject, context) => {
context.data.demo = true;
context.data['demo'] = true;
resolve(context);
},
{ delay: 0, timeout: 10 },
);

expect(result.data.demo).toBeTruthy();
expect(result.data['demo']).toBeTruthy();
});

it('Keeps track of options', async () => {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"allowUnusedLabels": false,
Expand Down
Loading