@ou-imdt/utils
Version:
Utility library for interactive media development
15 lines (14 loc) • 555 B
JavaScript
import splitPropertyPath from './splitPropertyPath';
import getObjectProperty from './getObjectProperty';
/**
* gets the target object(s) on a property path by splitting the path
* @param {string} path - a property path
* @returns {object}
*/
export default function getPropertyPathTarget(path = '', root) {
const parts = splitPropertyPath(path, { withGroups: true });
const prop = parts.pop().key;
const subpath = parts.reduce((str, { part }) => str += part, '');
const target = getObjectProperty(root, subpath);
return { target, prop };
}