UNPKG

873 BJavaScriptView Raw
1var castPath = require('./_castPath'),
2 isKey = require('./_isKey'),
3 last = require('./last'),
4 parent = require('./_parent'),
5 toKey = require('./_toKey');
6
7/** Used for built-in method references. */
8var objectProto = Object.prototype;
9
10/** Used to check objects for own properties. */
11var hasOwnProperty = objectProto.hasOwnProperty;
12
13/**
14 * The base implementation of `_.unset`.
15 *
16 * @private
17 * @param {Object} object The object to modify.
18 * @param {Array|string} path The property path to unset.
19 * @returns {boolean} Returns `true` if the property is deleted, else `false`.
20 */
21function baseUnset(object, path) {
22 path = isKey(path, object) ? [path] : castPath(path);
23 object = parent(object, path);
24
25 var key = toKey(last(path));
26 return !(object != null && hasOwnProperty.call(object, key)) || delete object[key];
27}
28
29module.exports = baseUnset;