source: node_modules/ramda/es/hasPath.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 _has from "./internal/_has.js";
3import isNil from "./isNil.js";
4/**
5 * Returns whether or not a path exists in an object. Only the object's
6 * own properties are checked.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.26.0
11 * @category Object
12 * @typedefn Idx = String | Int | Symbol
13 * @sig [Idx] -> {a} -> Boolean
14 * @param {Array} path The path to use.
15 * @param {Object} obj The object to check the path in.
16 * @return {Boolean} Whether the path exists.
17 * @see R.has
18 * @example
19 *
20 * R.hasPath(['a', 'b'], {a: {b: 2}}); // => true
21 * R.hasPath(['a', 'b'], {a: {b: undefined}}); // => true
22 * R.hasPath(['a', 'b'], {a: {c: 2}}); // => false
23 * R.hasPath(['a', 'b'], {}); // => false
24 */
25
26var hasPath =
27/*#__PURE__*/
28_curry2(function hasPath(_path, obj) {
29 if (_path.length === 0 || isNil(obj)) {
30 return false;
31 }
32
33 var val = obj;
34 var idx = 0;
35
36 while (idx < _path.length) {
37 if (!isNil(val) && _has(_path[idx], val)) {
38 val = val[_path[idx]];
39 idx += 1;
40 } else {
41 return false;
42 }
43 }
44
45 return true;
46});
47
48export default hasPath;
Note: See TracBrowser for help on using the repository browser.