https://github.com/kripod/record-like-deep-assign
Recursively assigns enumerable own properties of the given sources to a target object
https://github.com/kripod/record-like-deep-assign
Last synced: 11 months ago
JSON representation
Recursively assigns enumerable own properties of the given sources to a target object
- Host: GitHub
- URL: https://github.com/kripod/record-like-deep-assign
- Owner: kripod
- License: mit
- Created: 2020-08-09T18:38:23.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-08-09T19:28:27.000Z (almost 6 years ago)
- Last Synced: 2025-06-26T02:48:25.864Z (12 months ago)
- Language: TypeScript
- Size: 211 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Record-like deep assign
Recursively assigns enumerable own properties of the given sources to a target object.
- API inspired by [`Object.assign`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign), with source objects applied from left to right:
```js
import deepAssign from "record-like-deep-assign"
deepAssign(target, ...sources) // Returns `target`
```
- Plain objects are merged deeply:
```js
// Result: { x: { a: 1, b: 2 } }
deepAssign({ x: { a: 1 } }, { x: { b: 2 } })
```
- Arrays and constructor-instantiated objects are treated like primitives. They aren't merged but replaced in their entirely:
```js
// Result: { arr: ["c"] }
deepAssign({ arr: ["a", "b"] }, { arr: ["c"] })
// Result: { x: Date 1997-11-21 }
deepAssign({ x: new Date("1996-12-03") }, { x: new Date("1997-11-21") })
```
- Nullish sources are ignored:
```js
// Result: { a: 1, b: 2 }
deepAssign({ a: 1 }, null, undefined, { b: 2 })
```
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):