source: node_modules/ramda/es/path.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import 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
28var path =
29/*#__PURE__*/
30_curry2(function path(pathAr, obj) {
31 return paths([pathAr], obj)[0];
32});
33
34export default path;
Note: See TracBrowser for help on using the repository browser.