Files
ohif-viewer/platform/core/src/utils/resolveObjectPath.js
T

17 lines
510 B
JavaScript
Raw Normal View History

export default function resolveObjectPath(root, path, defaultValue) {
if (root !== null && typeof root === 'object' && typeof path === 'string') {
let value,
separator = path.indexOf('.');
if (separator >= 0) {
return resolveObjectPath(
root[path.slice(0, separator)],
path.slice(separator + 1, path.length),
defaultValue
);
}
value = root[path];
return value === undefined && defaultValue !== undefined
? defaultValue
: value;
}
}