Skip to content

Commit 09edbaf

Browse files
Added utils
1 parent fc35500 commit 09edbaf

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/utils/objects.util.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Find an object inside another object by a given path
3+
* @param $ref Path to find EX: '#/level1/level2/level3'
4+
* @param fullObject Full instance of the object
5+
*/
6+
export function findInObject($ref: string, fullObject: any): any {
7+
const path = $ref.split('/');
8+
9+
let child = path.shift(); // Skip the root (#)
10+
let currentPath = fullObject;
11+
while ((child = path.shift())) {
12+
if (!currentPath[child]) {
13+
return null;
14+
}
15+
currentPath = currentPath[child];
16+
}
17+
18+
return currentPath;
19+
}

0 commit comments

Comments
 (0)