sec-edgar-api
Version:
Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.
89 lines (88 loc) • 4.32 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var ReportTranslatedProxy_1 = require("./ReportTranslatedProxy");
/**
* Contains translated report and raw report with methods to access other reports
*/
var ReportWrapper = /** @class */ (function (_super) {
__extends(ReportWrapper, _super);
function ReportWrapper(report, reportRaw, reportMap) {
var _this = this;
var _a;
_this = _super.call(this, report) || this;
_this.report = report;
_this.reportMap = reportMap !== null && reportMap !== void 0 ? reportMap : new Map();
_this.reportRaw = reportRaw !== null && reportRaw !== void 0 ? reportRaw : {
cik: report.cik,
url: report.url,
dateFiled: report.dateFiled,
dateReport: report.dateReport,
fiscalPeriod: ((_a = report.fiscalPeriod) !== null && _a !== void 0 ? _a : ''),
fiscalYear: report.fiscalYear,
splitRatio: null,
splitDate: null,
};
return _this;
}
/**
* when using JSON.stringify on this class instance, it will stringify the report
*/
ReportWrapper.prototype.toJSON = function () {
return this.report;
};
ReportWrapper.prototype.getReportRaw = function () {
return this.reportRaw;
};
ReportWrapper.prototype.getReport = function () {
return this.report;
};
/**
* Gets report wrapper for prev or future report
*
* @param offset positive number returns future report, negative returns past
*/
ReportWrapper.prototype.getReportOffset = function (offset, reportType) {
var _a, _b;
var _c = this.report, fiscalPeriod = _c.fiscalPeriod, fiscalYear = _c.fiscalYear;
if (reportType === 'ANNUAL') {
return (_a = this.reportMap.get("".concat(fiscalYear + offset, "_FY"))) !== null && _a !== void 0 ? _a : null;
}
var period = fiscalPeriod === 'FY' ? 'Q4' : fiscalPeriod;
var currentQuarter = Number(period.substring(1));
var isCeilOffsetYear = currentQuarter + (offset % 4) > 4 || (offset < 0 && currentQuarter + (offset % 4) > 0);
var targetYear = isCeilOffsetYear ? fiscalYear + Math.ceil(offset / 4) : fiscalYear + Math.floor(offset / 4);
var targetQuarter = Math.abs(currentQuarter + offset < 0 ? ((currentQuarter + offset) % 4) + 4 : (currentQuarter + offset) % 4 || 4);
return (_b = this.reportMap.get("".concat(targetYear, "_Q").concat(targetQuarter))) !== null && _b !== void 0 ? _b : null;
};
/**
* Gets report wrappers in the same fiscal year as this report
*/
ReportWrapper.prototype.getReportsFiscalYearByPeriod = function (fiscalYear) {
var _a, _b, _c, _d, _e;
if (fiscalYear === void 0) { fiscalYear = this.report.fiscalYear; }
return {
FY: (_a = this.reportMap.get("".concat(fiscalYear, "_FY"))) !== null && _a !== void 0 ? _a : null,
Q1: (_b = this.reportMap.get("".concat(fiscalYear, "_Q1"))) !== null && _b !== void 0 ? _b : null,
Q2: (_c = this.reportMap.get("".concat(fiscalYear, "_Q2"))) !== null && _c !== void 0 ? _c : null,
Q3: (_d = this.reportMap.get("".concat(fiscalYear, "_Q3"))) !== null && _d !== void 0 ? _d : null,
Q4: (_e = this.reportMap.get("".concat(fiscalYear, "_Q4"))) !== null && _e !== void 0 ? _e : null,
};
};
return ReportWrapper;
}(ReportTranslatedProxy_1.default));
exports.default = ReportWrapper;