super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
46 lines (45 loc) • 1.62 kB
TypeScript
/**
* Creates an object with the same keys as object and values generated by
* running each own enumerable string keyed property of object through
* iteratee. The iteratee is invoked with three arguments:
* (value, key, object).
*
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns The new mapped object
*
* @example
* ```ts
* const users = {
* 'fred': { 'user': 'fred', 'age': 40 },
* 'pebbles': { 'user': 'pebbles', 'age': 1 }
* };
*
* mapValues(users, function(o) { return o.age; });
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*
* // The `_.property` iteratee shorthand.
* mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
* ```
*/
export declare function mapValues<T extends object, R>(object: T, iteratee: ((value: any, key: string, object: T) => R) | string): Record<string, R>;
/**
* Creates an object with the same values as object and keys generated
* by running each own enumerable string keyed property of object through
* iteratee. The iteratee is invoked with three arguments:
* (value, key, object).
*
* @param object - The object to iterate over
* @param iteratee - The function invoked per iteration
* @returns The new mapped object
*
* @example
* ```ts
* mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
* return key + value;
* });
* // => { 'a1': 1, 'b2': 2 }
* ```
*/
export declare function mapKeys<T extends object>(object: T, iteratee: (value: any, key: string, object: T) => string): Record<string, any>;