1 | var baseClone = require('./_baseClone'),
|
2 | baseUnset = require('./_baseUnset'),
|
3 | copyObject = require('./_copyObject'),
|
4 | flatRest = require('./_flatRest'),
|
5 | getAllKeysIn = require('./_getAllKeysIn');
|
6 |
|
7 | /** Used to compose bitmasks for cloning. */
|
8 | var CLONE_DEEP_FLAG = 1,
|
9 | CLONE_FLAT_FLAG = 2,
|
10 | CLONE_SYMBOLS_FLAG = 4;
|
11 |
|
12 | /**
|
13 | * The opposite of `_.pick`; this method creates an object composed of the
|
14 | * own and inherited enumerable property paths of `object` that are not omitted.
|
15 | *
|
16 | * **Note:** This method is considerably slower than `_.pick`.
|
17 | *
|
18 | * @static
|
19 | * @since 0.1.0
|
20 | * @memberOf _
|
21 | * @category Object
|
22 | * @param {Object} object The source object.
|
23 | * @param {...(string|string[])} [paths] The property paths to omit.
|
24 | * @returns {Object} Returns the new object.
|
25 | * @example
|
26 | *
|
27 | * var object = { 'a': 1, 'b': '2', 'c': 3 };
|
28 | *
|
29 | * _.omit(object, ['a', 'c']);
|
30 | * // => { 'b': '2' }
|
31 | */
|
32 | var omit = flatRest(function(object, paths) {
|
33 | var result = {};
|
34 | if (object == null) {
|
35 | return result;
|
36 | }
|
37 | copyObject(object, getAllKeysIn(object), result);
|
38 | result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG);
|
39 |
|
40 | var length = paths.length;
|
41 | while (length--) {
|
42 | baseUnset(result, paths[length]);
|
43 | }
|
44 | return result;
|
45 | });
|
46 |
|
47 | module.exports = omit;
|