UNPKG

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