Skip to content

fix(keys): skip key transformation for non-plain objects like Date (#356)#364

Open
MohammadYusif wants to merge 1 commit into
blakeembrey:mainfrom
MohammadYusif:fix/issue-356
Open

fix(keys): skip key transformation for non-plain objects like Date (#356)#364
MohammadYusif wants to merge 1 commit into
blakeembrey:mainfrom
MohammadYusif:fix/issue-356

Conversation

@MohammadYusif

Copy link
Copy Markdown

Summary

  • changeKeys treated Date (and any non-plain object) as a plain object to recurse into, because the isObject guard only checked !== null && typeof === "object"
  • This caused Date values to become empty {} objects, breaking prototype methods like .toISOString()
  • Non-plain objects (Date, RegExp, Map, Set, class instances) should be returned as-is

Changes

  • packages/change-case/src/keys.ts: added isPlainObject helper checking the prototype chain; added if (!isPlainObject(object)) return object guard after the array branch
  • packages/change-case/src/keys.spec.ts: added two regression tests for Date property and mixed Date + string property objects

Fixes #356

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.

change-case/keys fails on Date objects

1 participant