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.

29 lines
881 B

4 years ago
  1. import _curry3 from "./internal/_curry3.js";
  2. import defaultTo from "./defaultTo.js";
  3. import path from "./path.js";
  4. /**
  5. * If the given, non-null object has a value at the given path, returns the
  6. * value at that path. Otherwise returns the provided default value.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.18.0
  11. * @category Object
  12. * @typedefn Idx = String | Int
  13. * @sig a -> [Idx] -> {a} -> a
  14. * @param {*} d The default value.
  15. * @param {Array} p The path to use.
  16. * @param {Object} obj The object to retrieve the nested property from.
  17. * @return {*} The data at `path` of the supplied object or the default value.
  18. * @example
  19. *
  20. * R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
  21. * R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
  22. */
  23. var pathOr =
  24. /*#__PURE__*/
  25. _curry3(function pathOr(d, p, obj) {
  26. return defaultTo(d, path(p, obj));
  27. });
  28. export default pathOr;