_baseUnset.js 725 B

123456789101112131415161718192021222324
  1. var baseHas = require('./_baseHas'),
  2. castPath = require('./_castPath'),
  3. isKey = require('./_isKey'),
  4. last = require('./last'),
  5. parent = require('./_parent'),
  6. toKey = require('./_toKey');
  7. /**
  8. * The base implementation of `_.unset`.
  9. *
  10. * @private
  11. * @param {Object} object The object to modify.
  12. * @param {Array|string} path The path of the property to unset.
  13. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  14. */
  15. function baseUnset(object, path) {
  16. path = isKey(path, object) ? [path] : castPath(path);
  17. object = parent(object, path);
  18. var key = toKey(last(path));
  19. return !(object != null && baseHas(object, key)) || delete object[key];
  20. }
  21. module.exports = baseUnset;