rittenhop-dev/versions/5.94.2/node_modules/@aws-sdk/util-endpoints/dist-cjs/lib/getAttr.js
2024-09-23 19:40:12 -04:00

16 lines
593 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAttr = void 0;
const types_1 = require("../types");
const getAttrPathList_1 = require("./getAttrPathList");
const getAttr = (value, path) => (0, getAttrPathList_1.getAttrPathList)(path).reduce((acc, index) => {
if (typeof acc !== "object") {
throw new types_1.EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
}
else if (Array.isArray(acc)) {
return acc[parseInt(index)];
}
return acc[index];
}, value);
exports.getAttr = getAttr;