1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _has =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_has");
|
8 |
|
9 | var isNil =
|
10 | /*#__PURE__*/
|
11 | require("./isNil");
|
12 | /**
|
13 | * Returns whether or not a path exists in an object. Only the object's
|
14 | * own properties are checked.
|
15 | *
|
16 | * @func
|
17 | * @memberOf R
|
18 | * @since v0.26.0
|
19 | * @category Object
|
20 | * @typedefn Idx = String | Int
|
21 | * @sig [Idx] -> {a} -> Boolean
|
22 | * @param {Array} path The path to use.
|
23 | * @param {Object} obj The object to check the path in.
|
24 | * @return {Boolean} Whether the path exists.
|
25 | * @see R.has
|
26 | * @example
|
27 | *
|
28 | * R.hasPath(['a', 'b'], {a: {b: 2}}); // => true
|
29 | * R.hasPath(['a', 'b'], {a: {b: undefined}}); // => true
|
30 | * R.hasPath(['a', 'b'], {a: {c: 2}}); // => false
|
31 | * R.hasPath(['a', 'b'], {}); // => false
|
32 | */
|
33 |
|
34 |
|
35 | var hasPath =
|
36 | /*#__PURE__*/
|
37 | _curry2(function hasPath(_path, obj) {
|
38 | if (_path.length === 0 || isNil(obj)) {
|
39 | return false;
|
40 | }
|
41 |
|
42 | var val = obj;
|
43 | var idx = 0;
|
44 |
|
45 | while (idx < _path.length) {
|
46 | if (!isNil(val) && _has(_path[idx], val)) {
|
47 | val = val[_path[idx]];
|
48 | idx += 1;
|
49 | } else {
|
50 | return false;
|
51 | }
|
52 | }
|
53 |
|
54 | return true;
|
55 | });
|
56 |
|
57 | module.exports = hasPath; |
\ | No newline at end of file |