mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Bump to v3.8.0.
This commit is contained in:
26
internal/createObjectMapper.js
Normal file
26
internal/createObjectMapper.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import baseCallback from './baseCallback';
|
||||
import baseForOwn from './baseForOwn';
|
||||
|
||||
/**
|
||||
* Creates a function for `_.mapKeys` or `_.mapValues`.
|
||||
*
|
||||
* @private
|
||||
* @param {boolean} [isMapKeys] Specify mapping keys instead of values.
|
||||
* @returns {Function} Returns the new map function.
|
||||
*/
|
||||
function createObjectMapper(isMapKeys) {
|
||||
return function(object, iteratee, thisArg) {
|
||||
var result = {};
|
||||
iteratee = baseCallback(iteratee, thisArg, 3);
|
||||
|
||||
baseForOwn(object, function(value, key, object) {
|
||||
var mapped = iteratee(value, key, object);
|
||||
key = isMapKeys ? mapped : key;
|
||||
value = isMapKeys ? value : mapped;
|
||||
result[key] = value;
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export default createObjectMapper;
|
||||
Reference in New Issue
Block a user