safe-traverse.js 379 B

12345678910111213141516
  1. "use strict";
  2. var value = require("./valid-value")
  3. , isValue = require("./is-value");
  4. module.exports = function (obj /*, …names*/) {
  5. var length, current = 1;
  6. value(obj);
  7. length = arguments.length - 1;
  8. if (!length) return obj;
  9. while (current < length) {
  10. obj = obj[arguments[current++]];
  11. if (!isValue(obj)) return undefined;
  12. }
  13. return obj[arguments[current]];
  14. };