mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-24 09:49:06 +01:00
14 lines
404 B
TypeScript
14 lines
404 B
TypeScript
export function resolveObjPath(o: object, s: string): any {
|
|
s = s.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
|
|
s = s.replace(/^\./, ''); // strip a leading dot
|
|
var a = s.split('.');
|
|
for (var i = 0, n = a.length; i < n; ++i) {
|
|
var k = a[i];
|
|
if (k in o) {
|
|
o = o[k];
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
return o;
|
|
} |