main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var _isInteger =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./internal/_isInteger.js");
|
---|
8 |
|
---|
9 | var nth =
|
---|
10 | /*#__PURE__*/
|
---|
11 | require("./nth.js");
|
---|
12 | /**
|
---|
13 | * Retrieves the values at given paths of an object.
|
---|
14 | *
|
---|
15 | * @func
|
---|
16 | * @memberOf R
|
---|
17 | * @since v0.27.1
|
---|
18 | * @category Object
|
---|
19 | * @typedefn Idx = [String | Int | Symbol]
|
---|
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; |
---|
Note:
See
TracBrowser
for help on using the repository browser.