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