An open API service indexing awesome lists of open source software.

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

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)):



Kristóf Poduszló

🚧 💻 📖 ⚠️ 🤔 🚇

Pierre-Antoine Mills

🤔