-
Notifications
You must be signed in to change notification settings - Fork 5
feat(deepMerge): only merge plain objects #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@barso/forms
@barso/helpers
@barso/hooks
@barso/infra
@barso/ui
commit: |
There was a problem hiding this 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 modifies the deepMerge function to only deeply merge plain objects (object literals), while treating built-in objects like Date, Map, Set, and RegExp as atomic values that should be replaced rather than merged.
Key changes:
- Introduced a new
isPlainObjecthelper function that distinguishes plain objects from built-in objects and class instances - Updated
deepMergeto useisPlainObjectinstead ofisObjectfor merge decisions - Added comprehensive test coverage for the new behavior with various built-in object types
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/helpers/src/is.js | Added new isPlainObject function to check if a value is a plain object literal |
| packages/helpers/src/is.test.js | Added comprehensive tests for isPlainObject covering primitives, arrays, built-in objects, and custom prototypes |
| packages/helpers/src/merge.js | Updated deepMerge to use isPlainObject instead of isObject to prevent merging built-in objects |
| packages/helpers/src/merge.test.js | Added tests verifying that RegExp, Map, Set, and Date objects are replaced rather than merged |
Comments suppressed due to low confidence (1)
packages/helpers/src/merge.js:7
- The function documentation should be updated to clarify that it only deeply merges plain objects (object literals). Built-in objects like Date, Map, Set, and RegExp are replaced rather than merged. Consider updating the JSDoc to explain this behavior, for example: "Deeply merges two plain objects. Built-in objects (Date, Map, Set, RegExp, etc.) are replaced by the source value rather than merged."
/**
* Deeply merges two objects.
* @param {*} target - The target object to merge into.
* @param {*} source - The source object to merge from.
* @returns {*} - The merged object.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ee857e8 to
12c5bf3
Compare
No description provided.