Last active
April 26, 2024 23:04
-
-
Save juliandescottes/2c53afbaed9287de3cb4 to your computer and use it in GitHub Desktop.
getPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (object, path) { | |
var parts = path.split ? path.split(".") : path; | |
try { | |
var node = object; | |
parts.forEach(function (part) { | |
node = node[part]; | |
}); | |
return node; | |
} catch (e) { | |
console.error('Failed to get path : ' + path + ' in object : \n' + JSON.stringify(object)); | |
return null; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment