xatto
Version:
xatto is View Layer Library based on Function and Context using VirtualDOM. This is developed by forking from jorgebucaran/superfine.
29 lines (26 loc) • 501 B
text/typescript
/**
* Get an item from an object using separator notation.
*
* @typeparam {T}
* @param {any} target
* @param {string} key
* @param {string} separator
* @return {T}
*/
export function deepGet<T> (
target: any,
key: string,
separator: string = '.'
): T {
while (true) {
if (target == null) {
return target
}
const idx = key.indexOf(separator)
if (idx < 0) {
return target[key]
}
target = target[key.slice(0, idx)]
key = key.slice(idx + 1)
}
}