object/assign.js

  1. import { apply } from 'core/apply'
  2. /**
  3. * Replaces by an object assigning own enumerable string keyed properties of source objects to the destination object.<br />
  4. * Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
  5. * @function
  6. * @memberof object
  7. * @param {Object} object The object to modify.
  8. * @param {Array|string} path The path of the property to set.
  9. * @param {...Object} [sources] The source objects.
  10. * @return {Object} Returns the updated object.
  11. * @example assign({ nested: { a: 1, b: 2 } }, 'nested', { b: 3, c: 4 }) // => { nested: { a:1, b: 3, c: 4 } }
  12. * @see {@link https://mdn.io/Object.prototype.assign|Object.prototype.assign} for more information.
  13. * @since 0.1.12
  14. */
  15. const assign = apply((obj, ...args) => Object.assign({ ...obj }, ...args))
  16. export { assign }