UNPKG

928 BJavaScriptView Raw
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3");
4
5var defaultTo =
6/*#__PURE__*/
7require("./defaultTo");
8
9var path =
10/*#__PURE__*/
11require("./path");
12/**
13 * If the given, non-null object has a value at the given path, returns the
14 * value at that path. Otherwise returns the provided default value.
15 *
16 * @func
17 * @memberOf R
18 * @since v0.18.0
19 * @category Object
20 * @typedefn Idx = String | Int
21 * @sig a -> [Idx] -> {a} -> a
22 * @param {*} d The default value.
23 * @param {Array} p The path to use.
24 * @param {Object} obj The object to retrieve the nested property from.
25 * @return {*} The data at `path` of the supplied object or the default value.
26 * @example
27 *
28 * R.pathOr('N/A', ['a', 'b'], {a: {b: 2}}); //=> 2
29 * R.pathOr('N/A', ['a', 'b'], {c: {b: 2}}); //=> "N/A"
30 */
31
32
33var pathOr =
34/*#__PURE__*/
35_curry3(function pathOr(d, p, obj) {
36 return defaultTo(d, path(p, obj));
37});
38
39module.exports = pathOr;
\No newline at end of file