1234567891011121314151617181920212223 |
- 'use strict';
- function getPropertyByPath(source , path ) {
- if (typeof path === 'string' && source.hasOwnProperty(path)) {
- return source[path];
- }
- const parsedPath = typeof path === 'string' ? path.split('.') : path;
- return parsedPath.reduce((previous, key) => {
- if (previous === undefined) {
- return previous;
- }
- return previous[key];
- }, source);
- }
- module.exports = getPropertyByPath;
|