core/unset.js

  1. import { curry } from './curry'
  2. import { nav } from 'nav/nav'
  3. import { toPath } from 'immutadot-parser'
  4. /**
  5. * Removes the property at <code>path</code> of <code>object</code>.
  6. * @function
  7. * @memberof core
  8. * @param {Object} obj The object to modify.
  9. * @param {Array|string} path The path of the property to unset.
  10. * @return {Object} Returns the updated object.
  11. * @example unset({ nested: { prop: 'value' } }, 'nested.prop') // => { nested: {} }
  12. * @since 1.0.0
  13. */
  14. const unset = curry((obj, path) => nav(toPath(path))(obj).unset(), { fixedArity: true })
  15. export { unset }