mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-06 16:03:52 +00:00
19 lines
500 B
TypeScript
19 lines
500 B
TypeScript
/**
|
|
* Extracts a value from a nested object using a dot-separated path
|
|
*/
|
|
export function getPropertyFromPath<T extends object>(path: string, obj: T): any | undefined {
|
|
const keys = path.split('.');
|
|
let result: any = obj;
|
|
|
|
// iterate through variable parts, and look for the property in the given object
|
|
for (const key of keys) {
|
|
if (result && typeof result === 'object' && key in result) {
|
|
result = result[key];
|
|
} else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|