mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Bump to v3.0.0.
This commit is contained in:
51
object/omit.js
Normal file
51
object/omit.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import arrayMap from '../internal/arrayMap';
|
||||
import baseDifference from '../internal/baseDifference';
|
||||
import baseFlatten from '../internal/baseFlatten';
|
||||
import bindCallback from '../internal/bindCallback';
|
||||
import keysIn from './keysIn';
|
||||
import pickByArray from '../internal/pickByArray';
|
||||
import pickByCallback from '../internal/pickByCallback';
|
||||
|
||||
/**
|
||||
* The opposite of `_.pick`; this method creates an object composed of the
|
||||
* own and inherited enumerable properties of `object` that are not omitted.
|
||||
* Property names may be specified as individual arguments or as arrays of
|
||||
* property names. If `predicate` is provided it is invoked for each property
|
||||
* of `object` omitting the properties `predicate` returns truthy for. The
|
||||
* predicate is bound to `thisArg` and invoked with three arguments;
|
||||
* (value, key, object).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Object
|
||||
* @param {Object} object The source object.
|
||||
* @param {Function|...(string|string[])} [predicate] The function invoked per
|
||||
* iteration or property names to omit, specified as individual property
|
||||
* names or arrays of property names.
|
||||
* @param {*} [thisArg] The `this` binding of `predicate`.
|
||||
* @returns {Object} Returns the new object.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred', 'age': 40 };
|
||||
*
|
||||
* _.omit(object, 'age');
|
||||
* // => { 'user': 'fred' }
|
||||
*
|
||||
* _.omit(object, _.isNumber);
|
||||
* // => { 'user': 'fred' }
|
||||
*/
|
||||
function omit(object, predicate, thisArg) {
|
||||
if (object == null) {
|
||||
return {};
|
||||
}
|
||||
if (typeof predicate != 'function') {
|
||||
var props = arrayMap(baseFlatten(arguments, false, false, 1), String);
|
||||
return pickByArray(object, baseDifference(keysIn(object), props));
|
||||
}
|
||||
predicate = bindCallback(predicate, thisArg, 3);
|
||||
return pickByCallback(object, function(value, key, object) {
|
||||
return !predicate(value, key, object);
|
||||
});
|
||||
}
|
||||
|
||||
export default omit;
|
||||
Reference in New Issue
Block a user