object/mapValues.js

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