You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1018 B

4 years ago
  1. import _curry3 from "./internal/_curry3.js";
  2. import pathOr from "./pathOr.js";
  3. /**
  4. * If the given, non-null object has an own property with the specified name,
  5. * returns the value of that property. Otherwise returns the provided default
  6. * value.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.6.0
  11. * @category Object
  12. * @sig a -> String -> Object -> a
  13. * @param {*} val The default value.
  14. * @param {String} p The name of the property to return.
  15. * @param {Object} obj The object to query.
  16. * @return {*} The value of given property of the supplied object or the default value.
  17. * @example
  18. *
  19. * const alice = {
  20. * name: 'ALICE',
  21. * age: 101
  22. * };
  23. * const favorite = R.prop('favoriteLibrary');
  24. * const favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary');
  25. *
  26. * favorite(alice); //=> undefined
  27. * favoriteWithDefault(alice); //=> 'Ramda'
  28. */
  29. var propOr =
  30. /*#__PURE__*/
  31. _curry3(function propOr(val, p, obj) {
  32. return pathOr(val, [p], obj);
  33. });
  34. export default propOr;