@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
22 lines (21 loc) • 664 B
JavaScript
import { check } from '@augment-vir/assert';
/**
* Gets the value of a nested property within `Parent` by recursively accessing each key in `Keys`.
*
* @category Object
* @category Package : @augment-vir/common
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function getDeepValue(parent, keys) {
if (!keys.length) {
return parent;
}
const innerParent = parent;
const currentKey = keys[0];
if (currentKey != undefined && check.hasKey(innerParent, currentKey)) {
return getDeepValue(innerParent[currentKey], keys.slice(1));
}
else {
return undefined;
}
}