lib/dig.js
function getProp (obj, path, isArray) {
  var next;
  path = _.isString(path) ? path.split('.') : path;

  // We have more traversing to do
  if (path.length > 1) {
    next = path.shift();
    if (_.isArray(obj[next])) {
      isArray = true;
      var arr = _.compact(_.flatten(obj[next].map(function (el, i) {
        return getProp(el, _.clone(path), isArray);
      })));
      return arr.length ? arr : undefined;
    } else {
      if (!obj[next]) { return; }
      return getProp(obj[next], path, isArray);
    }

  // No more traversing. We can now target the final node with path[0]
  } else {
    next = path[0];
    // if we are at the end of the path and `obj` is an array
    if (_.isArray(obj)) {
      return _.pluck(obj, next);
    } else {
      if (!obj[next]) { return; }
      return isArray ? [obj[next]] : obj[next];
    }
  }
}
function getProp (obj, path, isArray) {
  var next;
  path = _.isString(path) ? path.split('.') : path;

  // We have more traversing to do
  if (path.length > 1) {
    next = path.shift();
    if (_.isArray(obj[next])) {
      isArray = true;
      var arr = _.compact(_.flatten(obj[next].map(function (el, i) {
        return getProp(el, _.clone(path), isArray);
      })));
      return arr.length ? arr : undefined;
    } else {
      if (!obj[next]) { return; }
      return getProp(obj[next], path, isArray);
    }

  // No more traversing. We can now target the final node with path[0]
  } else {
    next = path[0];
    // if we are at the end of the path and `obj` is an array
    if (_.isArray(obj)) {
      return _.pluck(obj, next);
    } else {
      if (!obj[next]) { return; }
      return isArray ? [obj[next]] : obj[next];
    }
  }
}
function getProp ( obj , path , isArray ) { var next ; path = _ . isString ( path ) ? path . split ( '.' ) : path ; // We have more traversing to do if ( path . length > 1 ) { next = path . shift ( ) ; if ( _ . isArray ( obj [ next ] ) ) { isArray = true ; var arr = _ . compact ( _ . flatten ( obj [ next ] . map ( function ( el , i ) { return getProp ( el , _ . clone ( path ) , isArray ) ; } ) ) ) ; return arr . length ? arr : undefined ; } else { if ( ! obj [ next ] ) { return ; } return getProp ( obj [ next ] , path , isArray ) ; } // No more traversing. We can now target the final node with path[0] } else { next = path [ 0 ] ; // if we are at the end of the path and `obj` is an array if ( _ . isArray ( obj ) ) { return _ . pluck ( obj , next ) ; } else { if ( ! obj [ next ] ) { return ; } return isArray ? [ obj [ next ] ] : obj [ next ] ; } } }
returns value of property at path, or array of properties if there is an array in the path
returns value of property at path or array of properties if there is an array in the path