record-like-deep-assign
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Record-like deep assign

Recursively assigns enumerable own properties of the given sources to a target object.

  • API inspired by Object.assign, with source objects applied from left to right:

    import deepAssign from "record-like-deep-assign"
     
    deepAssign(target, ...sources) // Returns `target`
  • Plain objects are merged deeply:

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

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

    // Result: { a: 1, b: 2 }
    deepAssign({ a: 1 }, null, undefined, { b: 2 })

Contributors

Thanks goes to these wonderful people (emoji key):


Kristóf Poduszló

🚧 💻 📖 ⚠️ 🤔 🚇

Pierre-Antoine Mills

🤔

Readme

Keywords

Package Sidebar

Install

npm i record-like-deep-assign

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

13.7 kB

Total Files

14

Last publish

Collaborators

  • kripod