UNPKG

819 BJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4
5var paths =
6/*#__PURE__*/
7require("./paths");
8/**
9 * Retrieve the value at a given path.
10 *
11 * @func
12 * @memberOf R
13 * @since v0.2.0
14 * @category Object
15 * @typedefn Idx = String | Int
16 * @sig [Idx] -> {a} -> a | Undefined
17 * @param {Array} path The path to use.
18 * @param {Object} obj The object to retrieve the nested property from.
19 * @return {*} The data at `path`.
20 * @see R.prop, R.nth
21 * @example
22 *
23 * R.path(['a', 'b'], {a: {b: 2}}); //=> 2
24 * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined
25 * R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1
26 * R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2
27 */
28
29
30var path =
31/*#__PURE__*/
32_curry2(function path(pathAr, obj) {
33 return paths([pathAr], obj)[0];
34});
35
36module.exports = path;
\No newline at end of file