hasIn.js 961 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import _curry2 from "./internal/_curry2.js";
  2. import isNil from "./isNil.js";
  3. /**
  4. * Returns whether or not an object or its prototype chain has a property with
  5. * the specified name
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.7.0
  10. * @category Object
  11. * @sig s -> {s: x} -> Boolean
  12. * @param {String} prop The name of the property to check for.
  13. * @param {Object} obj The object to query.
  14. * @return {Boolean} Whether the property exists.
  15. * @example
  16. *
  17. * function Rectangle(width, height) {
  18. * this.width = width;
  19. * this.height = height;
  20. * }
  21. * Rectangle.prototype.area = function() {
  22. * return this.width * this.height;
  23. * };
  24. *
  25. * const square = new Rectangle(2, 2);
  26. * R.hasIn('width', square); //=> true
  27. * R.hasIn('area', square); //=> true
  28. */
  29. var hasIn =
  30. /*#__PURE__*/
  31. _curry2(function hasIn(prop, obj) {
  32. if (isNil(obj)) {
  33. return false;
  34. }
  35. return prop in obj;
  36. });
  37. export default hasIn;