Skip to content

feat: add type guards for various data types and implement behavioral tests#9

Merged
Coderrob merged 10 commits intomainfrom
human-cleanup
Apr 2, 2026
Merged

feat: add type guards for various data types and implement behavioral tests#9
Coderrob merged 10 commits intomainfrom
human-cleanup

Conversation

@Coderrob
Copy link
Copy Markdown
Owner

@Coderrob Coderrob commented Apr 2, 2026

  • Implemented isNonEmptyArray, isNonEmptyArrayOf, isNonEmptyString, isNull, isNullOrUndefined, isNullish, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isThenable, isUndefined, isValidDate guards.
  • Created comprehensive tests for each guard using Vitest, ensuring positive and negative cases are covered.
  • Introduced helper functions for behavioral contract testing to streamline test case definitions.
  • Enhanced existing guards with improved type checks and error handling.
  • Added type tests to validate type narrowing functionality for various guards.
  • Updated index.ts to export new guards and maintain module integrity.

… tests

- Implemented `isNonEmptyArray`, `isNonEmptyArrayOf`, `isNonEmptyString`, `isNull`, `isNullOrUndefined`, `isNullish`, `isNumber`, `isObject`, `isPlainObject`, `isPromise`, `isRegExp`, `isSet`, `isString`, `isSymbol`, `isThenable`, `isUndefined`, `isValidDate` guards.
- Created comprehensive tests for each guard using Vitest, ensuring positive and negative cases are covered.
- Introduced helper functions for behavioral contract testing to streamline test case definitions.
- Enhanced existing guards with improved type checks and error handling.
- Added type tests to validate type narrowing functionality for various guards.
- Updated `index.ts` to export new guards and maintain module integrity.
Copilot AI review requested due to automatic review settings April 2, 2026 04:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the library’s type guard surface area and modernizes the project’s build/test tooling to support behavioral runtime tests, type-narrowing checks, and dual ESM/CommonJS package output.

Changes:

  • Added/updated guards and extracted shared internal helpers (e.g., callable-property and plain-object helpers).
  • Replaced the previous monolithic Jest suite with Vitest-based behavioral contract tests plus separate test-d type-narrowing checks.
  • Switched packaging/build to tsup, updated exports for ESM/CJS interop, and strengthened CI (matrix Node versions + coverage + package smoke test).

Reviewed changes

Copilot reviewed 57 out of 58 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tsconfig.type-tests.json Adds a dedicated TS config for type-narrowing (“type tests”) compilation.
test-d/narrowing.types.ts Adds compile-time narrowing assertions for several guards and guard factories.
src/index.ts Exports isPlainObject from the public entrypoint.
src/guards/isValidDate.ts Refactors guard logic to an explicit isDate early-return before checking getTime().
src/guards/isUndefined.ts Simplifies undefined check to strict equality.
src/guards/isThenable.ts Refactors thenable detection to reuse a shared callable-property helper.
src/guards/isPlainObject.ts Introduces isPlainObject using shared object helper utilities.
src/guards/isObject.ts Refactors isObject to use shared object helper utilities.
src/guards/isNonEmptyArrayOf.ts Refactors for clearer early returns and adjusts guard parameter typing.
src/guards/isNonEmptyArray.ts Refactors for clearer early returns.
src/guards/isDefined.ts Implements isDefined via isNullish for consistency.
src/guards/isArrayOf.ts Refactors for clearer early returns and adjusts guard parameter typing.
src/guards/internal/objectHelpers.ts Adds shared helpers for “non-array object” and “plain prototype” checks.
src/guards/internal/hasCallableProperty.ts Adds shared helper for checking whether a property resolves to a callable value.
src/guards/getEnumValues.ts Tightens typing around enum value extraction helpers.
src/guards/createTypeGuard.ts Adjusts constructor parameter typing (readonly intersection) without changing behavior.
src/guards/createEnumGuard.ts Refactors enum value candidate checks using existing primitive guards and avoids barrel cycles.
src/tests/support/test-helpers.ts Adds reusable behavioral-contract helpers and shared fixtures for runtime guard tests.
src/tests/runtime.test.ts Adds a single runtime test entrypoint that imports all per-guard test files.
src/tests/isValidDate.test.ts Adds behavioral contract tests for isValidDate.
src/tests/isUndefined.test.ts Adds behavioral contract tests for isUndefined.
src/tests/isThenable.test.ts Adds behavioral contract tests for isThenable, including function-thenable coverage.
src/tests/isSymbol.test.ts Adds behavioral contract tests for isSymbol.
src/tests/isString.test.ts Adds behavioral contract tests for isString.
src/tests/isSet.test.ts Adds behavioral contract tests for isSet.
src/tests/isRegExp.test.ts Adds behavioral contract tests for isRegExp.
src/tests/isPromise.test.ts Adds behavioral contract tests for isPromise.
src/tests/isPlainObject.test.ts Adds behavioral contract tests for isPlainObject.
src/tests/isObject.test.ts Adds behavioral contract tests for isObject.
src/tests/isNumber.test.ts Adds behavioral contract tests for isNumber.
src/tests/isNullOrUndefined.test.ts Adds behavioral contract tests for isNullOrUndefined.
src/tests/isNullish.test.ts Adds behavioral contract tests for isNullish.
src/tests/isNull.test.ts Adds behavioral contract tests for isNull.
src/tests/isNonEmptyString.test.ts Adds behavioral contract tests for isNonEmptyString.
src/tests/isNonEmptyArrayOf.test.ts Adds behavioral contract tests for isNonEmptyArrayOf.
src/tests/isNonEmptyArray.test.ts Adds behavioral contract tests for isNonEmptyArray.
src/tests/isNaN.test.ts Adds behavioral contract tests for isNaN.
src/tests/isMap.test.ts Adds behavioral contract tests for isMap.
src/tests/isInteger.test.ts Adds behavioral contract tests for isInteger.
src/tests/isFunction.test.ts Adds behavioral contract tests for isFunction.
src/tests/isFiniteNumber.test.ts Adds behavioral contract tests for isFiniteNumber.
src/tests/isError.test.ts Adds behavioral contract tests for isError.
src/tests/isDefined.test.ts Adds behavioral contract tests for isDefined.
src/tests/isDate.test.ts Adds behavioral contract tests for isDate.
src/tests/isBoolean.test.ts Adds behavioral contract tests for isBoolean.
src/tests/isBigInt.test.ts Adds behavioral contract tests for isBigInt.
src/tests/isArrayOf.test.ts Adds behavioral contract tests for isArrayOf.
src/tests/isArray.test.ts Adds behavioral contract tests for isArray.
src/tests/guards.test.ts Removes the previous large combined test file (replaced by per-guard tests).
src/tests/createTypeGuard.test.ts Adds behavioral contract and naming tests for createTypeGuard.
src/tests/createEnumGuard.test.ts Adds behavioral contract and naming tests for createEnumGuard.
scripts/check-package-interop.mjs Adds an ESM/CJS interop smoke test against built dist/ artifacts.
scripts/check-file-coverage.mjs Adds a per-file coverage threshold validator based on coverage-summary output.
README.md Updates package name, installation/import examples, guard list, and dev commands.
package.json Migrates build/test tooling (tsup + vitest), updates exports for ESM/CJS, and adds CI-oriented scripts.
eslint.config.mjs Updates flat ESLint config, adds ignores, and relaxes JSDoc rule in tests/type-tests.
.github/workflows/ci.yml Expands CI to node-version matrix and adds typecheck/build/package/coverage steps.
Comments suppressed due to low confidence (1)

src/guards/isPlainObject.ts:32

  • isPlainObject currently has the same implementation as isObject (both check for a non-null, non-array object whose prototype is Object.prototype or null). If both exports are intended to remain public, this duplication is easy to drift over time and it’s unclear to consumers when to use which guard. Consider either (a) making one guard an alias/re-export of the other to keep behavior in sync, or (b) adjusting one guard’s semantics and/or JSDoc to clearly differentiate them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Coderrob Coderrob merged commit f91dc97 into main Apr 2, 2026
2 checks passed
@Coderrob Coderrob deleted the human-cleanup branch April 2, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants