Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
lodash.mapvalues
Advanced tools
The lodash.mapvalues package is a utility library that provides a method to create a new object with the same keys as the original object, but with values generated by running each own enumerable string-keyed property of the object through a provided function.
Transform Object Values
This feature allows you to transform the values of an object based on a function. In this example, the values of the 'users' object are transformed to just their ages.
const mapValues = require('lodash.mapvalues');
const users = { 'fred': { 'age': 40 }, 'pebbles': { 'age': 1 } };
const result = mapValues(users, function(o) { return o.age; });
console.log(result); // { 'fred': 40, 'pebbles': 1 }
Modify Values Based on Key
This feature allows you to modify the values of an object based on both the value and the key. In this example, the values are transformed to a string that includes both the key and the age.
const mapValues = require('lodash.mapvalues');
const users = { 'fred': { 'age': 40 }, 'pebbles': { 'age': 1 } };
const result = mapValues(users, function(o, key) { return key + ' is ' + o.age; });
console.log(result); // { 'fred': 'fred is 40', 'pebbles': 'pebbles is 1' }
Ramda is a functional programming library for JavaScript that provides a similar function called 'R.map'. It allows you to map over the values of an object, but it also offers a broader range of functional programming utilities compared to lodash.mapvalues.
Underscore is another utility library that provides a similar function called '_.mapObject'. It offers a wide range of utility functions for JavaScript, similar to Lodash, but with a different API and some differences in performance and functionality.
The lodash method _.mapValues
exported as a Node.js module.
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save lodash.mapvalues
In Node.js:
var mapValues = require('lodash.mapvalues');
See the documentation or package source for more details.
FAQs
The lodash method `_.mapValues` exported as a module.
We found that lodash.mapvalues demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.