UNPKG

typedash

Version:

modern, type-safe collection of utility functions

21 lines (19 loc) 932 B
import { t as objectEntries } from "./objectEntries-D0fnOPZh.js"; import { t as objectFromEntries } from "./objectFromEntries-9X94Rk5A.js"; //#region src/functions/mapValues/mapValues.ts /** * Returns a new object with the same keys as the given object, but with each value mapped to a new value as returned by the given mapper function. * @param object The object to map. * @param mapperFunction The function used to map each value. * @returns A new object with the same keys as the given object, but with each value mapped to a new value as returned by the given mapper function. * @example * ```ts * mapValues({ a: 1, b: 2, c: 3 }, (value) => value * 2) // { a: 2, b: 4, c: 6 } * ``` */ function mapValues(object, mapperFunction) { return objectFromEntries(objectEntries(object).map(([key, value]) => [key, mapperFunction(value, key)])); } //#endregion export { mapValues as t }; //# sourceMappingURL=mapValues-EtORmvab.js.map