artdaq_node_server  v1_00_09
 All Classes Namespaces Files Variables Pages
result.js
1 var castPath = require('./_castPath'),
2  isFunction = require('./isFunction'),
3  toKey = require('./_toKey');
4 
34 function result(object, path, defaultValue) {
35  path = castPath(path, object);
36 
37  var index = -1,
38  length = path.length;
39 
40  // Ensure the loop is entered when path is empty.
41  if (!length) {
42  length = 1;
43  object = undefined;
44  }
45  while (++index < length) {
46  var value = object == null ? undefined : object[toKey(path[index])];
47  if (value === undefined) {
48  index = length;
49  value = defaultValue;
50  }
51  object = isFunction(value) ? value.call(object) : value;
52  }
53  return object;
54 }
55 
56 module.exports = result;