has.js 542 B

12345678910111213141516171819
  1. var _has = require('./_has.js');
  2. var _toPath = require('./_toPath.js');
  3. // Shortcut function for checking if an object has a given property directly on
  4. // itself (in other words, not on a prototype). Unlike the internal `has`
  5. // function, this public version can also traverse nested properties.
  6. function has(obj, path) {
  7. path = _toPath(path);
  8. var length = path.length;
  9. for (var i = 0; i < length; i++) {
  10. var key = path[i];
  11. if (!_has(obj, key)) return false;
  12. obj = obj[key];
  13. }
  14. return !!length;
  15. }
  16. module.exports = has;