Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-nested-value

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-nested-value - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

package.json
{
"name": "get-nested-value",
"version": "1.0.0",
"version": "1.0.1",
"description": "Utility package to get deeply nested values from objects. Support arrays.",

@@ -5,0 +5,0 @@ "main": "readme.js",

@@ -34,11 +34,19 @@ /**

*/
const getNestedValue = (path, object) => {
var getNestedValue = function (path, object) {
if (!Array.isArray(path) && typeof path !== 'string') {
throw Error('The package get-nested-value received a non-contract path. Please provide a string or an array!');
}
return (Array.isArray(path) ? path : path.split('.'))
.reduce((prev, cur) =>
(prev && prev[cur] !== undefined ? prev[cur] : undefined), object);
var searchPath = path;
if (!Array.isArray(path)) {
searchPath = searchPath.split('.');
}
return searchPath
.reduce(function (prev, cur) {
if (prev && prev[cur] !== undefined) {
return prev[cur];
}
return undefined;
}, object);
};
module.exports = getNestedValue;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc