2016-10-10 03:43:44 +02:00
|
|
|
var arrayMap = require('./_arrayMap'),
|
2016-11-16 01:59:39 +01:00
|
|
|
baseClone = require('./_baseClone'),
|
|
|
|
baseUnset = require('./_baseUnset'),
|
|
|
|
castPath = require('./_castPath'),
|
|
|
|
copyObject = require('./_copyObject'),
|
2016-10-10 03:43:44 +02:00
|
|
|
flatRest = require('./_flatRest'),
|
2016-11-16 01:59:39 +01:00
|
|
|
getAllKeysIn = require('./_getAllKeysIn');
|
|
|
|
|
|
|
|
/** Used to compose bitmasks for cloning. */
|
|
|
|
var CLONE_DEEP_FLAG = 1,
|
|
|
|
CLONE_FLAT_FLAG = 2,
|
|
|
|
CLONE_SYMBOLS_FLAG = 4;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The opposite of `_.pick`; this method creates an object composed of the
|
2016-11-16 01:59:39 +01:00
|
|
|
* own and inherited enumerable property paths of `object` that are not omitted.
|
|
|
|
*
|
|
|
|
* **Note:** This method is considerably slower than `_.pick`.
|
2016-10-10 03:43:44 +02:00
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @since 0.1.0
|
|
|
|
* @memberOf _
|
|
|
|
* @category Object
|
|
|
|
* @param {Object} object The source object.
|
2016-11-16 01:59:39 +01:00
|
|
|
* @param {...(string|string[])} [paths] The property paths to omit.
|
2016-10-10 03:43:44 +02:00
|
|
|
* @returns {Object} Returns the new object.
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* var object = { 'a': 1, 'b': '2', 'c': 3 };
|
|
|
|
*
|
|
|
|
* _.omit(object, ['a', 'c']);
|
|
|
|
* // => { 'b': '2' }
|
|
|
|
*/
|
2016-11-16 01:59:39 +01:00
|
|
|
var omit = flatRest(function(object, paths) {
|
|
|
|
var result = {};
|
2016-10-10 03:43:44 +02:00
|
|
|
if (object == null) {
|
2016-11-16 01:59:39 +01:00
|
|
|
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]);
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
2016-11-16 01:59:39 +01:00
|
|
|
return result;
|
2016-10-10 03:43:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = omit;
|