diff options
Diffstat (limited to 'node_modules/lodash/omit.js')
-rw-r--r-- | node_modules/lodash/omit.js | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/node_modules/lodash/omit.js b/node_modules/lodash/omit.js index 38f919092..ecc809731 100644 --- a/node_modules/lodash/omit.js +++ b/node_modules/lodash/omit.js @@ -1,21 +1,28 @@ var arrayMap = require('./_arrayMap'), - baseDifference = require('./_baseDifference'), - basePick = require('./_basePick'), + baseClone = require('./_baseClone'), + baseUnset = require('./_baseUnset'), + castPath = require('./_castPath'), + copyObject = require('./_copyObject'), flatRest = require('./_flatRest'), - getAllKeysIn = require('./_getAllKeysIn'), - toKey = require('./_toKey'); + getAllKeysIn = require('./_getAllKeysIn'); + +/** Used to compose bitmasks for cloning. */ +var CLONE_DEEP_FLAG = 1, + CLONE_FLAT_FLAG = 2, + CLONE_SYMBOLS_FLAG = 4; /** * The opposite of `_.pick`; this method creates an object composed of the - * own and inherited enumerable string keyed properties of `object` that are - * not omitted. + * own and inherited enumerable property paths of `object` that are not omitted. + * + * **Note:** This method is considerably slower than `_.pick`. * * @static * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property identifiers to omit. + * @param {...(string|string[])} [paths] The property paths to omit. * @returns {Object} Returns the new object. * @example * @@ -24,12 +31,26 @@ var arrayMap = require('./_arrayMap'), * _.omit(object, ['a', 'c']); * // => { 'b': '2' } */ -var omit = flatRest(function(object, props) { +var omit = flatRest(function(object, paths) { + var result = {}; if (object == null) { - return {}; + return result; + } + var bitmask = CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG; + paths = arrayMap(paths, function(path) { + path = castPath(path, object); + bitmask |= (path.length > 1 ? CLONE_DEEP_FLAG : 0); + return path; + }); + + copyObject(object, getAllKeysIn(object), result); + result = baseClone(result, bitmask); + + var length = paths.length; + while (length--) { + baseUnset(result, paths[length]); } - props = arrayMap(props, toKey); - return basePick(object, baseDifference(getAllKeysIn(object), props)); + return result; }); module.exports = omit; |