summaryrefslogtreecommitdiff
path: root/node_modules/@jet/environment/json/reader/traverse.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@jet/environment/json/reader/traverse.js')
-rw-r--r--node_modules/@jet/environment/json/reader/traverse.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/node_modules/@jet/environment/json/reader/traverse.js b/node_modules/@jet/environment/json/reader/traverse.js
new file mode 100644
index 0000000..9f5d1ad
--- /dev/null
+++ b/node_modules/@jet/environment/json/reader/traverse.js
@@ -0,0 +1,36 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.traverse = void 0;
+const optional_1 = require("../../types/optional");
+const key_path_1 = require("./key-path");
+function traverse(object, keyPath) {
+ if (typeof object !== "object") {
+ return object;
+ }
+ if (!(0, optional_1.isSome)(object)) {
+ return object;
+ }
+ const keys = (0, key_path_1.keysOf)(keyPath);
+ switch (keys.length) {
+ case 0:
+ return object;
+ case 1:
+ return object[keys[0]];
+ default:
+ // eslint-disable-next-line no-case-declarations
+ let currentObject = object;
+ for (const key of keys) {
+ const currentValue = currentObject[key];
+ if (typeof currentValue !== "object") {
+ return currentValue;
+ }
+ if (!(0, optional_1.isSome)(currentValue)) {
+ return currentValue;
+ }
+ currentObject = currentValue;
+ }
+ return currentObject;
+ }
+}
+exports.traverse = traverse;
+//# sourceMappingURL=traverse.js.map \ No newline at end of file