sec-edgar-api
Version:
Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.
38 lines (37 loc) • 3.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCurrentFilingsDaily = void 0;
function parseCurrentFilingsDaily(params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var xml = params.xml;
var csv = (_a = xml.split('<hr>')[1]) !== null && _a !== void 0 ? _a : '';
var lines = csv.split('\n').slice(0, -1);
var _k = (_b = xml.match(/<strong>.{1,20}?<\/strong>/g)) !== null && _b !== void 0 ? _b : [], _l = _k[0], matchHtml = _l === void 0 ? '' : _l, _m = _k[1], totalHtml = _m === void 0 ? '' : _m;
var date = (_e = (_d = (_c = xml.split('of matches for')) === null || _c === void 0 ? void 0 : _c[1].split('is', 1)) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.trim();
var matchCount = Number((_g = (_f = matchHtml.split('>')[1]) === null || _f === void 0 ? void 0 : _f.split('<')[0]) === null || _g === void 0 ? void 0 : _g.trim()) || 0;
var totalCount = Number((_j = (_h = totalHtml.split('>')[1]) === null || _h === void 0 ? void 0 : _h.split('<')[0]) === null || _j === void 0 ? void 0 : _j.trim()) || 0;
var entries = lines.map(function (line) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
var parts = line.split('<a ');
var partDate = (_a = parts[0]) !== null && _a !== void 0 ? _a : '';
var partNameCik = (_b = parts[parts.length - 1]) !== null && _b !== void 0 ? _b : '';
var partAccessionForm = (_f = (_e = (_d = ((_c = parts[1]) !== null && _c !== void 0 ? _c : '').split('/Archives/edgar/data/')[1]) === null || _d === void 0 ? void 0 : _d.split('/')) === null || _e === void 0 ? void 0 : _e[1]) !== null && _f !== void 0 ? _f : '';
var partNameCikParts = partNameCik.split('</a>');
var _r = (_g = partAccessionForm === null || partAccessionForm === void 0 ? void 0 : partAccessionForm.split('>')) !== null && _g !== void 0 ? _g : [], accession = _r[0], formUnfiltered = _r[1];
var accessionNumber = ((_h = accession === null || accession === void 0 ? void 0 : accession.substring(0, accession.lastIndexOf('-'))) !== null && _h !== void 0 ? _h : '').trim();
var form = ((_j = formUnfiltered === null || formUnfiltered === void 0 ? void 0 : formUnfiltered.replace(/</g, '')) !== null && _j !== void 0 ? _j : '').trim();
var companyCik = Number((_m = (_l = (_k = partNameCikParts[0]) === null || _k === void 0 ? void 0 : _k.split('>')[1]) === null || _l === void 0 ? void 0 : _l.trim()) !== null && _m !== void 0 ? _m : '');
var companyName = (_p = (_o = partNameCikParts[1]) === null || _o === void 0 ? void 0 : _o.trim()) !== null && _p !== void 0 ? _p : '';
var filedDate = (_q = partDate.trim()) !== null && _q !== void 0 ? _q : '';
var _s = filedDate.split('-'), month = _s[0], day = _s[1], year = _s[2];
return {
accessionNumber: accessionNumber,
form: form,
companyCik: companyCik,
companyName: companyName,
filedDate: "".concat(year, "-").concat(month, "-").concat(day),
};
});
return { date: date, matchCount: matchCount, totalCount: totalCount, entries: entries };
}
exports.parseCurrentFilingsDaily = parseCurrentFilingsDaily;