UNPKG

foop

Version:

interfaces that describe their intentions.

43 lines (39 loc) 1.11 kB
const ObjectKeys = require('../../util/keys') const toObj = require('../../cast/toObj') /** * The opposite of `mapValue` this method creates an object with the * same values as `object` and keys generated by running each own enumerable * string keyed property of `object` thru `iteratee`. The iteratee is invoked * with three arguments: (value, key, object). * @since 5.0.0-beta.6 * @memberOf loop * @alias mapObjKeys * * @param {Object} object The object to iterate over. * @param {Function} iteratee The function invoked per iteration. * @return {Object} Returns the new mapped object. * * @fork 3.8.0 * @category Object * * @see mapValue * * @example * * var concatKey = (value, key) => key + value) * mapKey({ 'a': 1, 'b': 2 }, concatKey) * //=> { 'a1': 1, 'b2': 2 } * */ function mapObjKey(object, iteratee) { const obj = toObj(object) const result = {} const keys = ObjectKeys(obj) for (let i = 0; i < keys.length; i++) { const key = keys[i] const value = obj[key] result[iteratee(value, key, obj)] = value } return result } module.exports = mapObjKey