core/set.js

  1. import { apply } from 'path/apply'
  2. const setOperation = (obj, prop, _, value) => { obj[prop] = value }
  3. /**
  4. * Sets the value at <code>path</code> of <code>obj</code>.
  5. * @function
  6. * @memberof core
  7. * @param {*} obj The object to modify.
  8. * @param {string|Array} path The path of the property to set.
  9. * @param {*} value The value to set.
  10. * @return {*} Returns the updated object.
  11. * @example set({ nested: { prop: 'old' } }, 'nested.prop', 'new') // => { nested: { prop: 'new' } }
  12. * @since 1.0.0
  13. */
  14. const set = apply(setOperation)
  15. export { set }