mirror of
https://github.com/rxliuli/apps.apple.com.git
synced 2025-11-10 01:00:33 +00:00
init commit
This commit is contained in:
36
node_modules/@jet/environment/json/reader/traverse.js
generated
vendored
Normal file
36
node_modules/@jet/environment/json/reader/traverse.js
generated
vendored
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user