get-nested-value
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"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; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20046
105
52