1 | import _curry2 from "./internal/_curry2.js";
|
---|
2 | import paths from "./paths.js";
|
---|
3 | /**
|
---|
4 | * Retrieves the value at a given path. The nodes of the path can be arbitrary strings or non-negative integers.
|
---|
5 | * For anything else, the value is unspecified. Integer paths are meant to index arrays, strings are meant for objects.
|
---|
6 | *
|
---|
7 | * @func
|
---|
8 | * @memberOf R
|
---|
9 | * @since v0.2.0
|
---|
10 | * @category Object
|
---|
11 | * @typedefn Idx = String | Int | Symbol
|
---|
12 | * @sig [Idx] -> {a} -> a | Undefined
|
---|
13 | * @sig Idx = String | NonNegativeInt
|
---|
14 | * @param {Array} path The path to use.
|
---|
15 | * @param {Object} obj The object or array to retrieve the nested property from.
|
---|
16 | * @return {*} The data at `path`.
|
---|
17 | * @see R.prop, R.nth, R.assocPath, R.dissocPath
|
---|
18 | * @example
|
---|
19 | *
|
---|
20 | * R.path(['a', 'b'], {a: {b: 2}}); //=> 2
|
---|
21 | * R.path(['a', 'b'], {c: {b: 2}}); //=> undefined
|
---|
22 | * R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}); //=> 1
|
---|
23 | * R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}); //=> 2
|
---|
24 | * R.path([2], {'2': 2}); //=> 2
|
---|
25 | * R.path([-2], {'-2': 'a'}); //=> undefined
|
---|
26 | */
|
---|
27 |
|
---|
28 | var path =
|
---|
29 | /*#__PURE__*/
|
---|
30 | _curry2(function path(pathAr, obj) {
|
---|
31 | return paths([pathAr], obj)[0];
|
---|
32 | });
|
---|
33 |
|
---|
34 | export default path; |
---|