Skip to content

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

License

Notifications You must be signed in to change notification settings

kripod/record-like-deep-assign

Repository files navigation

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

🤔

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published