utils
Version:
Fast, generic JavaScript/node.js utility functions.
27 lines (21 loc) • 591 B
JavaScript
;
var forOwn = require('./forOwn');
var iterator = require('make-iterator');
/**
* Returns new object where each value is the result of
* calling the a `callback` function.
*
* @param {Object} obj The object to iterate over
* @param {Function} `cb` Callback function
* @param {Object} thisArg Invocation context of `cb`
* @return {Object}
* @api public
*/
module.exports = function mapValues(obj, cb, thisArg) {
var fn = iterator(cb, thisArg);
var res = {};
forOwn(obj, function (val, key, orig) {
res[key] = fn(val, key, orig);
});
return res;
};