You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

  1. var baseAssignValue = require('./_baseAssignValue'),
  2. baseForOwn = require('./_baseForOwn'),
  3. baseIteratee = require('./_baseIteratee');
  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 {Function} [iteratee=_.identity] The function invoked per iteration.
  16. * @returns {Object} Returns the new mapped object.
  17. * @see _.mapValues
  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. baseForOwn(object, function(value, key, object) {
  29. baseAssignValue(result, iteratee(value, key, object), value);
  30. });
  31. return result;
  32. }
  33. module.exports = mapKeys;