path.js 666 B

12345678910111213141516171819202122232425262728293031
  1. var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
  2. Gun.chain.path = function(field, opt){
  3. var back = this, gun = back, tmp;
  4. if(typeof field === 'string'){
  5. tmp = field.split(opt || '.');
  6. if(1 === tmp.length){
  7. gun = back.get(field);
  8. return gun;
  9. }
  10. field = tmp;
  11. }
  12. if(field instanceof Array){
  13. if(field.length > 1){
  14. gun = back;
  15. var i = 0, l = field.length;
  16. for(i; i < l; i++){
  17. //gun = gun.get(field[i], (i+1 === l)? cb : null, opt);
  18. gun = gun.get(field[i]);
  19. }
  20. } else {
  21. gun = back.get(field[0]);
  22. }
  23. return gun;
  24. }
  25. if(!field && 0 != field){
  26. return back;
  27. }
  28. gun = back.get(''+field);
  29. return gun;
  30. }