UNPKG

896 BJavaScriptView Raw
1
2var Gun = require('./core');
3Gun.chain.path = function(field, cb, opt){
4 var back = this, gun = back, tmp;
5 opt = opt || {}; opt.path = true;
6 if(gun === gun._.root){if(cb){cb({err: Gun.log("Can't do that on root instance.")})}return gun}
7 if(typeof field === 'string'){
8 tmp = field.split(opt.split || '.');
9 if(1 === tmp.length){
10 gun = back.get(field, cb, opt);
11 gun._.opt = opt;
12 return gun;
13 }
14 field = tmp;
15 }
16 if(field instanceof Array){
17 if(field.length > 1){
18 gun = back;
19 var i = 0, l = field.length;
20 for(i; i < l; i++){
21 gun = gun.get(field[i], (i+1 === l)? cb : null, opt);
22 }
23 //gun.back = back; // TODO: API change!
24 } else {
25 gun = back.get(field[0], cb, opt);
26 }
27 gun._.opt = opt;
28 return gun;
29 }
30 if(!field && 0 != field){
31 return back;
32 }
33 gun = back.get(''+field, cb, opt);
34 gun._.opt = opt;
35 return gun;
36}
37
\No newline at end of file