Bump to v4.1.0.

This commit is contained in:
John-David Dalton
2016-01-26 01:49:35 -08:00
parent d8d0500f37
commit bbd78fee4d
765 changed files with 1993 additions and 1233 deletions

View File

@@ -1,23 +1,16 @@
var arrayReduce = require('./internal/arrayReduce'),
keys = require('./keys');
/** Used for built-in method references. */
var objectProto = global.Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
var constant = require('./constant'),
createInverter = require('./_createInverter'),
identity = require('./identity');
/**
* Creates an object composed of the inverted keys and values of `object`.
* If `object` contains duplicate values, subsequent values overwrite property
* assignments of previous values unless `multiVal` is `true`.
* assignments of previous values.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to invert.
* @param {boolean} [multiVal] Allow multiple values per key.
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
* @returns {Object} Returns the new inverted object.
* @example
*
@@ -25,26 +18,9 @@ var hasOwnProperty = objectProto.hasOwnProperty;
*
* _.invert(object);
* // => { '1': 'c', '2': 'b' }
*
* // with `multiVal`
* _.invert(object, true);
* // => { '1': ['a', 'c'], '2': ['b'] }
*/
function invert(object, multiVal, guard) {
return arrayReduce(keys(object), function(result, key) {
var value = object[key];
if (multiVal && !guard) {
if (hasOwnProperty.call(result, value)) {
result[value].push(key);
} else {
result[value] = [key];
}
}
else {
result[value] = key;
}
return result;
}, {});
}
var invert = createInverter(function(result, value, key) {
result[value] = key;
}, constant(identity));
module.exports = invert;