2154b4a5e446fc40bea7702e75d1493301107ac6
[platform/framework/web/crosswalk-tizen.git] /
1 var arrayMap = require('../internal/arrayMap'),
2     baseDifference = require('../internal/baseDifference'),
3     baseFlatten = require('../internal/baseFlatten'),
4     bindCallback = require('../internal/bindCallback'),
5     keysIn = require('./keysIn'),
6     pickByArray = require('../internal/pickByArray'),
7     pickByCallback = require('../internal/pickByCallback'),
8     restParam = require('../function/restParam');
9
10 /**
11  * The opposite of `_.pick`; this method creates an object composed of the
12  * own and inherited enumerable properties of `object` that are not omitted.
13  * Property names may be specified as individual arguments or as arrays of
14  * property names. If `predicate` is provided it is invoked for each property
15  * of `object` omitting the properties `predicate` returns truthy for. The
16  * predicate is bound to `thisArg` and invoked with three arguments:
17  * (value, key, object).
18  *
19  * @static
20  * @memberOf _
21  * @category Object
22  * @param {Object} object The source object.
23  * @param {Function|...(string|string[])} [predicate] The function invoked per
24  *  iteration or property names to omit, specified as individual property
25  *  names or arrays of property names.
26  * @param {*} [thisArg] The `this` binding of `predicate`.
27  * @returns {Object} Returns the new object.
28  * @example
29  *
30  * var object = { 'user': 'fred', 'age': 40 };
31  *
32  * _.omit(object, 'age');
33  * // => { 'user': 'fred' }
34  *
35  * _.omit(object, _.isNumber);
36  * // => { 'user': 'fred' }
37  */
38 var omit = restParam(function(object, props) {
39   if (object == null) {
40     return {};
41   }
42   if (typeof props[0] != 'function') {
43     var props = arrayMap(baseFlatten(props), String);
44     return pickByArray(object, baseDifference(keysIn(object), props));
45   }
46   var predicate = bindCallback(props[0], props[1], 3);
47   return pickByCallback(object, function(value, key, object) {
48     return !predicate(value, key, object);
49   });
50 });
51
52 module.exports = omit;