object/mapValues.js

  1. import { lodashFpConvertOptions } from '../consts'
  2. import mapValues from 'lodash/fp/mapValues'
  3. import update from '../object/update'
  4. const rawMapValues = mapValues.convert(lodashFpConvertOptions)
  5. /**
  6. * Creates an object with the same keys as object and values generated by
  7. * running each own enumerable string keyed property of object thru iteratee.
  8. * The iteratee is invoked with three arguments: (value, key, object).
  9. * @function mapValues
  10. * @memberof object
  11. * @param {Object} object The object to modify.
  12. * @param {Array|string} path The path of the property to set.
  13. * @param {function} [iteratee={@link https://lodash.com/docs#identity|lodash.identity}] The function invoked per iteration.
  14. * @return {Object} Returns the updated object.
  15. * @example mapValues({ nested: { a: 1, b: 2, c: 3 } }, 'nested', v => v * v) // => { nested: { a:1, b: 4, c: 9 } }
  16. * @example mapValues({ nested: { a: { age: 40, name: 'John' }, b: { age: 30, name: 'Alice' } } }, 'nested', 'age')
  17. * // => { nested: { a: 40, b: 30 } }
  18. * @see {@link https://lodash.com/docs#mapValues|lodash.mapValues} for more information.
  19. * @see {@link https://lodash.com/docs#identity|lodash.identity} for more information.
  20. * @see {@link object.update|update} for more information.
  21. * @since 0.1.12
  22. */
  23. export default update(rawMapValues)