Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
chain-able-deps / src / loop / map / mapObjVals.ts
Size: Mime:
import ObjectKeys from '../../util/keys'
import { AnyObj } from '../../_typings'
import { MapObjValuesIteratee } from './typings.loop.map'

/**
 * Creates an array of values by running each property of `object` thru
 * `iteratee`. The iteratee is invoked with three arguments: (value, key, object).
 *
 * @name mapObjVals
 * @since 5.0.0-beta.6
 * @memberOf loop
 *
 * @param object The object to iterate over.
 * @param iteratee The function invoked per iteration.
 * @return Returns the new mapped array.
 *
 * @func
 * @category Object
 *
 * {@link https://github.com/lodash/lodash/blob/master/map.js lodash-map}
 * @see {@link lodash-map}
 *
 * @example
 *
 *   const square = n => n * n
 *   map({ 'a': 4, 'b': 8 }, square)
 *   //=> [16, 64] (iteration order is not guaranteed)
 *
 */
function mapObjectValues(object: AnyObj, iteratee: MapObjValuesIteratee) {
  const props = ObjectKeys(object)
  const result = new Array(props.length)

  for (let index = 0; index < props.length; index++) {
    const key = props[index]
    const value = object[key]
    result[index] = iteratee(value, key, object)
  }

  return result
}

export default mapObjectValues