UNPKG

typedash

Version:

modern, type-safe collection of utility functions

26 lines (24 loc) 1.08 kB
const require_objectEntries = require('./objectEntries-Dx2VL-5Q.cjs'); const require_objectFromEntries = require('./objectFromEntries-CFhk9KlT.cjs'); //#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 require_objectFromEntries.objectFromEntries(require_objectEntries.objectEntries(object).map(([key, value]) => [key, mapperFunction(value, key)])); } //#endregion Object.defineProperty(exports, 'mapValues', { enumerable: true, get: function () { return mapValues; } }); //# sourceMappingURL=mapValues-xS7C28iZ.cjs.map