1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _isInteger =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_isInteger");
|
8 |
|
9 | var nth =
|
10 | /*#__PURE__*/
|
11 | require("./nth");
|
12 | /**
|
13 | * Retrieves the values at given paths of an object.
|
14 | *
|
15 | * @func
|
16 | * @memberOf R
|
17 | * @since v0.27.0
|
18 | * @category Object
|
19 | * @typedefn Idx = [String | Int]
|
20 | * @sig [Idx] -> {a} -> [a | Undefined]
|
21 | * @param {Array} pathsArray The array of paths to be fetched.
|
22 | * @param {Object} obj The object to retrieve the nested properties from.
|
23 | * @return {Array} A list consisting of values at paths specified by "pathsArray".
|
24 | * @see R.path
|
25 | * @example
|
26 | *
|
27 | * R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, 3]
|
28 | * R.paths([['a', 'b'], ['p', 'r']], {a: {b: 2}, p: [{q: 3}]}); //=> [2, undefined]
|
29 | */
|
30 |
|
31 |
|
32 | var paths =
|
33 | /*#__PURE__*/
|
34 | _curry2(function paths(pathsArray, obj) {
|
35 | return pathsArray.map(function (paths) {
|
36 | var val = obj;
|
37 | var idx = 0;
|
38 | var p;
|
39 |
|
40 | while (idx < paths.length) {
|
41 | if (val == null) {
|
42 | return;
|
43 | }
|
44 |
|
45 | p = paths[idx];
|
46 | val = _isInteger(p) ? nth(p, val) : val[p];
|
47 | idx += 1;
|
48 | }
|
49 |
|
50 | return val;
|
51 | });
|
52 | });
|
53 |
|
54 | module.exports = paths; |
\ | No newline at end of file |