this repo has no description
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.traverse = void 0;
4const optional_1 = require("../../types/optional");
5const key_path_1 = require("./key-path");
6function traverse(object, keyPath) {
7 if (typeof object !== "object") {
8 return object;
9 }
10 if (!(0, optional_1.isSome)(object)) {
11 return object;
12 }
13 const keys = (0, key_path_1.keysOf)(keyPath);
14 switch (keys.length) {
15 case 0:
16 return object;
17 case 1:
18 return object[keys[0]];
19 default:
20 // eslint-disable-next-line no-case-declarations
21 let currentObject = object;
22 for (const key of keys) {
23 const currentValue = currentObject[key];
24 if (typeof currentValue !== "object") {
25 return currentValue;
26 }
27 if (!(0, optional_1.isSome)(currentValue)) {
28 return currentValue;
29 }
30 currentObject = currentValue;
31 }
32 return currentObject;
33 }
34}
35exports.traverse = traverse;
36//# sourceMappingURL=traverse.js.map