32edea040c79b7f328c18a56522a30e8230461ba
[platform/framework/web/crosswalk-tizen.git] /
1 var baseCallback = require('../internal/baseCallback'),
2     baseForOwn = require('../internal/baseForOwn');
3
4 /**
5  * Creates an object with the same keys as `object` and values generated by
6  * running each own enumerable property of `object` through `iteratee`. The
7  * iteratee function is bound to `thisArg` and invoked with three arguments:
8  * (value, key, object).
9  *
10  * If a property name is provided for `iteratee` the created `_.property`
11  * style callback returns the property value of the given element.
12  *
13  * If a value is also provided for `thisArg` the created `_.matchesProperty`
14  * style callback returns `true` for elements that have a matching property
15  * value, else `false`.
16  *
17  * If an object is provided for `iteratee` the created `_.matches` style
18  * callback returns `true` for elements that have the properties of the given
19  * object, else `false`.
20  *
21  * @static
22  * @memberOf _
23  * @category Object
24  * @param {Object} object The object to iterate over.
25  * @param {Function|Object|string} [iteratee=_.identity] The function invoked
26  *  per iteration.
27  * @param {*} [thisArg] The `this` binding of `iteratee`.
28  * @returns {Object} Returns the new mapped object.
29  * @example
30  *
31  * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
32  *   return n * 3;
33  * });
34  * // => { 'a': 3, 'b': 6 }
35  *
36  * var users = {
37  *   'fred':    { 'user': 'fred',    'age': 40 },
38  *   'pebbles': { 'user': 'pebbles', 'age': 1 }
39  * };
40  *
41  * // using the `_.property` callback shorthand
42  * _.mapValues(users, 'age');
43  * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
44  */
45 function mapValues(object, iteratee, thisArg) {
46   var result = {};
47   iteratee = baseCallback(iteratee, thisArg, 3);
48
49   baseForOwn(object, function(value, key, object) {
50     result[key] = iteratee(value, key, object);
51   });
52   return result;
53 }
54
55 module.exports = mapValues;