sec-edgar-api
Version:
Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.
51 lines (50 loc) • 1.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.utilMap = void 0;
function expandMap(map) {
var _a, _b;
var mapExpanded = {};
for (var key in map) {
var groups = [];
for (var _i = 0, _c = map[key]; _i < _c.length; _i++) {
var group = _c[_i];
var calculations = [];
for (var _d = 0, group_1 = group; _d < group_1.length; _d++) {
var calculation = group_1[_d];
var key_1 = calculation[0];
var weight = Number((_a = calculation[1]) !== null && _a !== void 0 ? _a : 1);
var isRequired = Boolean((_b = calculation[2]) !== null && _b !== void 0 ? _b : false);
calculations.push({ key: key_1, weight: weight, isRequired: isRequired });
}
groups.push({ calculation: calculations });
}
mapExpanded[key] = { groups: groups };
}
return mapExpanded;
}
function condenseMap(map) {
var mapCondensed = {};
for (var key in map) {
var groupsArr = [];
for (var _i = 0, _a = map[key].groups; _i < _a.length; _i++) {
var group = _a[_i];
var groupArr = [];
for (var _b = 0, _c = group.calculation; _b < _c.length; _b++) {
var _d = _c[_b], key_2 = _d.key, weight = _d.weight, isRequired = _d.isRequired;
var row = [key_2, weight, Number(isRequired)];
groupArr.push(row);
}
groupsArr.push(groupArr);
}
mapCondensed[key] = groupsArr;
}
return mapCondensed;
}
/**
* Used for expanding and condensing calculation maps. Calculation maps are used in secEdgarApi.getReports
* to map values from the SEC to the reports.
*/
exports.utilMap = {
expandMap: expandMap,
condenseMap: condenseMap,
};
;