UNPKG

441 BJavaScriptView Raw
1"use strict";
2
3/**
4* get "nested" object property
5*/
6
7function dive(obj) { //..., path
8 var parts = [].slice.call(arguments, 1);
9 for(let part of parts) {
10 if(part == null) return;
11 if(obj == null) return;
12
13 if(obj[part] != null) {
14 obj = obj[part];
15 continue;
16 }
17
18 for(let spart of String(part).split('.')) {
19 if(obj == null) return;
20 obj = obj[spart];
21 }
22 }
23 return obj;
24}
25
26module.exports = dive;