Skip to content

Commit 2a40bca

Browse files
committed
Build
1 parent f2d4c01 commit 2a40bca

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

dist/absurdum.cjs

+21
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,26 @@ function mapKeys (object, func) {
15131513
);
15141514
}
15151515

1516+
/**
1517+
* MapKeys iterates over an object and applies a function to each value
1518+
*
1519+
* @param {Object} object input object
1520+
* @param {Function} func map function
1521+
* @returns {Object} object with mutated values
1522+
*
1523+
* @example
1524+
* const result = objects.mapValues({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
1525+
* console.log(result);
1526+
* > { a: neat_1, b: neat_2, c: neat_3 }
1527+
*/
1528+
function mapValues (object, func) {
1529+
if (typeof func !== 'function') { return object; }
1530+
return Object.entries(object).reduce((acc, [key, value]) => ({
1531+
...acc,
1532+
[key]: func(value, key, object)
1533+
}), {});
1534+
}
1535+
15161536
/**
15171537
* Merge recursively merges object properties from all supplied objects with object values
15181538
* being merged recursively and other value types overridden when applied from left to right.
@@ -1633,6 +1653,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16331653
invert: invert,
16341654
keys: keys,
16351655
mapKeys: mapKeys,
1656+
mapValues: mapValues,
16361657
merge: merge,
16371658
pick: pick,
16381659
values: values

dist/absurdum.esm.js

+21
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,26 @@ function mapKeys (object, func) {
15091509
);
15101510
}
15111511

1512+
/**
1513+
* MapKeys iterates over an object and applies a function to each value
1514+
*
1515+
* @param {Object} object input object
1516+
* @param {Function} func map function
1517+
* @returns {Object} object with mutated values
1518+
*
1519+
* @example
1520+
* const result = objects.mapValues({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
1521+
* console.log(result);
1522+
* > { a: neat_1, b: neat_2, c: neat_3 }
1523+
*/
1524+
function mapValues (object, func) {
1525+
if (typeof func !== 'function') { return object; }
1526+
return Object.entries(object).reduce((acc, [key, value]) => ({
1527+
...acc,
1528+
[key]: func(value, key, object)
1529+
}), {});
1530+
}
1531+
15121532
/**
15131533
* Merge recursively merges object properties from all supplied objects with object values
15141534
* being merged recursively and other value types overridden when applied from left to right.
@@ -1629,6 +1649,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
16291649
invert: invert,
16301650
keys: keys,
16311651
mapKeys: mapKeys,
1652+
mapValues: mapValues,
16321653
merge: merge,
16331654
pick: pick,
16341655
values: values

docs/objects/mapValues.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# objects.mapValues
2+
3+
<!-- div class="doc-container" -->
4+
5+
<!-- div -->
6+
7+
8+
<!-- div -->
9+
10+
<h3 id="mapvaluesobject-func"><code>mapValues(object, func)</code></h3>
11+
12+
MapKeys iterates over an object and applies a function to each value
13+
14+
#### Arguments
15+
1. `object` *(Object)*: input object
16+
2. `func` *(Function)*: map function
17+
18+
#### Returns
19+
*(Object)*: object with mutated values
20+
21+
#### Example
22+
```js
23+
const result = objects.mapValues({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
24+
console.log(result);
25+
> { a: neat_1, b: neat_2, c: neat_3 }
26+
```
27+
---
28+
29+
<!-- /div -->
30+
31+
<!-- /div -->
32+
33+
<!-- /div -->

src/objects/mapValues.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* MapKeys iterates over an object and applies a function to each value
3+
*
4+
* @param {Object} object input object
5+
* @param {Function} func map function
6+
* @returns {Object} object with mutated values
7+
*
8+
* @example
9+
* const result = objects.mapValues({ a: 1, b: 2, c: 3 }, value => `neat_${value}`);
10+
* console.log(result);
11+
* > { a: neat_1, b: neat_2, c: neat_3 }
12+
*/
13+
export function mapValues(object: any, func: Function): any;

0 commit comments

Comments
 (0)