my-idlers/node_modules/collect.js/dist/helpers/nestedValue.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

20 lines
432 B
JavaScript
Vendored

'use strict';
/**
* Get value of a nested property
*
* @param mainObject
* @param key
* @returns {*}
*/
module.exports = function nestedValue(mainObject, key) {
try {
return key.split('.').reduce(function (obj, property) {
return obj[property];
}, mainObject);
} catch (err) {
// If we end up here, we're not working with an object, and @var mainObject is the value itself
return mainObject;
}
};