1 | import baseForOwn from './_baseForOwn';
|
2 | import baseIteratee from './_baseIteratee';
|
3 |
|
4 | /**
|
5 | * The opposite of `_.mapValues`; this method creates an object with the
|
6 | * same values as `object` and keys generated by running each own enumerable
|
7 | * string keyed property of `object` thru `iteratee`. The iteratee is invoked
|
8 | * with three arguments: (value, key, object).
|
9 | *
|
10 | * @static
|
11 | * @memberOf _
|
12 | * @since 3.8.0
|
13 | * @category Object
|
14 | * @param {Object} object The object to iterate over.
|
15 | * @param {Array|Function|Object|string} [iteratee=_.identity]
|
16 | * The function invoked per iteration.
|
17 | * @returns {Object} Returns the new mapped object.
|
18 | * @example
|
19 | *
|
20 | * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
21 | * return key + value;
|
22 | * });
|
23 | * // => { 'a1': 1, 'b2': 2 }
|
24 | */
|
25 | function mapKeys(object, iteratee) {
|
26 | var result = {};
|
27 | iteratee = baseIteratee(iteratee, 3);
|
28 |
|
29 | baseForOwn(object, function(value, key, object) {
|
30 | result[iteratee(value, key, object)] = value;
|
31 | });
|
32 | return result;
|
33 | }
|
34 |
|
35 | export default mapKeys;
|