mapValues.js

  1. import mapValuesLimit from './mapValuesLimit';
  2. import doLimit from './internal/doLimit';
  3. /**
  4. * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.
  5. *
  6. * Produces a new Object by mapping each value of `obj` through the `iteratee`
  7. * function. The `iteratee` is called each `value` and `key` from `obj` and a
  8. * callback for when it has finished processing. Each of these callbacks takes
  9. * two arguments: an `error`, and the transformed item from `obj`. If `iteratee`
  10. * passes an error to its callback, the main `callback` (for the `mapValues`
  11. * function) is immediately called with the error.
  12. *
  13. * Note, the order of the keys in the result is not guaranteed. The keys will
  14. * be roughly in the order they complete, (but this is very engine-specific)
  15. *
  16. * @name mapValues
  17. * @static
  18. * @memberOf module:Collections
  19. * @method
  20. * @category Collection
  21. * @param {Object} obj - A collection to iterate over.
  22. * @param {AsyncFunction} iteratee - A function to apply to each value and key
  23. * in `coll`.
  24. * The iteratee should complete with the transformed value as its result.
  25. * Invoked with (value, key, callback).
  26. * @param {Function} [callback] - A callback which is called when all `iteratee`
  27. * functions have finished, or an error occurs. `result` is a new object consisting
  28. * of each key from `obj`, with each transformed value on the right-hand side.
  29. * Invoked with (err, result).
  30. * @example
  31. *
  32. * async.mapValues({
  33. * f1: 'file1',
  34. * f2: 'file2',
  35. * f3: 'file3'
  36. * }, function (file, key, callback) {
  37. * fs.stat(file, callback);
  38. * }, function(err, result) {
  39. * // result is now a map of stats for each file, e.g.
  40. * // {
  41. * // f1: [stats for file1],
  42. * // f2: [stats for file2],
  43. * // f3: [stats for file3]
  44. * // }
  45. * });
  46. */
  47. export default doLimit(mapValuesLimit, Infinity);