1
0

safe-traverse.js 338 B

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