sec-edgar-api 0.3.4 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/build/services/DocumentParser/DocumentParser.d.ts +17 -1
  2. package/build/services/DocumentParser/DocumentParser.js +17 -2
  3. package/build/services/DocumentParser/DocumentXmlSplitter.d.ts +17 -0
  4. package/build/services/DocumentParser/DocumentXmlSplitter.js +38 -0
  5. package/build/services/DocumentParser/ObjectUtil.d.ts +20 -0
  6. package/build/services/DocumentParser/ObjectUtil.js +60 -0
  7. package/build/services/DocumentParser/XBRLParser/HeaderParser.d.ts +38 -0
  8. package/build/services/DocumentParser/XBRLParser/HeaderParser.js +138 -0
  9. package/build/services/DocumentParser/XBRLParser/InstanceParser.d.ts +6 -0
  10. package/build/services/DocumentParser/XBRLParser/InstanceParser.js +106 -0
  11. package/build/services/DocumentParser/XBRLParser/LinkbaseParser.d.ts +13 -0
  12. package/build/services/DocumentParser/XBRLParser/LinkbaseParser.js +98 -0
  13. package/build/services/DocumentParser/XBRLParser/SchemaParser.d.ts +11 -0
  14. package/build/services/DocumentParser/XBRLParser/SchemaParser.js +142 -0
  15. package/build/services/DocumentParser/XBRLParser/XBRLParser.d.ts +34 -0
  16. package/build/services/DocumentParser/XBRLParser/XBRLParser.js +68 -0
  17. package/build/services/DocumentParser/XBRLParser/util-xbrl.d.ts +17 -0
  18. package/build/services/DocumentParser/XBRLParser/util-xbrl.js +50 -0
  19. package/build/services/DocumentParser/XMLParser.d.ts +9 -38
  20. package/build/services/DocumentParser/XMLParser.js +87 -280
  21. package/build/services/DocumentParser/XMLParserLegacy.d.ts +43 -0
  22. package/build/services/DocumentParser/XMLParserLegacy.js +308 -0
  23. package/build/services/DocumentParser/parsers/index.d.ts +10 -0
  24. package/build/services/DocumentParser/parsers/index.js +10 -0
  25. package/build/services/DocumentParser/parsers/parse-companies.d.ts +5 -0
  26. package/build/services/DocumentParser/parsers/parse-companies.js +52 -0
  27. package/build/services/DocumentParser/parsers/parse-current-filings-xbrl.d.ts +2 -0
  28. package/build/services/DocumentParser/parsers/parse-current-filings-xbrl.js +104 -0
  29. package/build/services/DocumentParser/parsers/parse-current-filings.d.ts +2 -0
  30. package/build/services/DocumentParser/parsers/parse-current-filings.js +76 -0
  31. package/build/services/DocumentParser/parsers/parse-form-10k.d.ts +1 -1
  32. package/build/services/DocumentParser/parsers/parse-form-10k.js +2 -2
  33. package/build/services/DocumentParser/parsers/parse-form-13g.d.ts +1 -1
  34. package/build/services/DocumentParser/parsers/parse-form-13g.js +2 -2
  35. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +1 -1
  36. package/build/services/DocumentParser/parsers/parse-form-4.js +2 -2
  37. package/build/services/DocumentParser/parsers/parse-form-def14a.d.ts +1 -1
  38. package/build/services/DocumentParser/parsers/parse-form-def14a.js +2 -2
  39. package/build/services/DocumentParser/parsers/parse-insider-transaction.d.ts +7 -0
  40. package/build/services/DocumentParser/parsers/parse-insider-transaction.js +199 -0
  41. package/build/services/DocumentParser/parsers/parse-xbrl.d.ts +8 -0
  42. package/build/services/DocumentParser/parsers/parse-xbrl.js +179 -0
  43. package/build/services/HtmlTableExtractor/HtmlTableExtractor.d.ts +45 -0
  44. package/build/services/HtmlTableExtractor/HtmlTableExtractor.js +430 -0
  45. package/build/services/HtmlTableExtractor/index.d.ts +2 -0
  46. package/build/services/HtmlTableExtractor/index.js +4 -0
  47. package/build/services/ReportRawBuilder/FactGrouper.js +6 -6
  48. package/build/services/ReportRawBuilder/FactSplitAdjuster.js +2 -1
  49. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +82 -15
  50. package/build/services/SecEdgarApi/SecEdgarApi.js +170 -21
  51. package/build/types/company-search.type.d.ts +5 -0
  52. package/build/types/company-search.type.js +2 -0
  53. package/build/types/current-filings.type.d.ts +57 -0
  54. package/build/types/current-filings.type.js +2 -0
  55. package/build/types/index.d.ts +3 -0
  56. package/build/types/index.js +3 -0
  57. package/build/types/insider-transaction.type.d.ts +32 -0
  58. package/build/types/insider-transaction.type.js +2 -0
  59. package/build/types/parsed-filings.type.d.ts +3 -3
  60. package/build/types/xbrl.type.d.ts +155 -0
  61. package/build/types/xbrl.type.js +2 -0
  62. package/build/util/constants.d.ts +2 -0
  63. package/build/util/constants.js +5 -0
  64. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseForm4 = void 0;
4
- var XMLParser_1 = require("../XMLParser");
4
+ var XMLParserLegacy_1 = require("../XMLParserLegacy");
5
5
  /**
6
6
  * Form 4 - Insider Transactions
7
7
  *
@@ -9,7 +9,7 @@ var XMLParser_1 = require("../XMLParser");
9
9
  */
10
10
  function parseForm4(params, xmlParser) {
11
11
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
12
- if (xmlParser === void 0) { xmlParser = new XMLParser_1.default(); }
12
+ if (xmlParser === void 0) { xmlParser = new XMLParserLegacy_1.default(); }
13
13
  var xml = params.xml;
14
14
  var textMap = xmlParser.getTableTextMap({ xml: xml, parentPath: 'html.body' });
15
15
  var getTextBetween = function (text, before, after) {
@@ -1,5 +1,5 @@
1
1
  import { FormDef14aData, XMLParams } from '../../../types';
2
- import XMLParser from '../XMLParser';
2
+ import XMLParser from '../XMLParserLegacy';
3
3
  /**
4
4
  * Form DEF 14a - Proxy Statement
5
5
  *
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseFormDef14a = void 0;
4
- var XMLParser_1 = require("../XMLParser");
4
+ var XMLParserLegacy_1 = require("../XMLParserLegacy");
5
5
  /**
6
6
  * Form DEF 14a - Proxy Statement
7
7
  *
@@ -9,7 +9,7 @@ var XMLParser_1 = require("../XMLParser");
9
9
  */
10
10
  function parseFormDef14a(params, xmlParser) {
11
11
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
12
- if (xmlParser === void 0) { xmlParser = new XMLParser_1.default(); }
12
+ if (xmlParser === void 0) { xmlParser = new XMLParserLegacy_1.default(); }
13
13
  var xml = params.xml;
14
14
  var doc = xmlParser.getDocumentNode({ xml: xml });
15
15
  var tables = doc.parseTables();
@@ -0,0 +1,7 @@
1
+ import { XMLParams } from '../../../types';
2
+ import { InsiderTransaction, Issuer, Owner } from '../../../types/insider-transaction.type';
3
+ export declare function parseInsiderTransactions(params: XMLParams): {
4
+ transactions: InsiderTransaction[];
5
+ owners: Owner[];
6
+ issuers: Issuer[];
7
+ };
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseInsiderTransactions = void 0;
4
+ var HtmlTableExtractor_1 = require("../../HtmlTableExtractor");
5
+ function parseInsiderTransactions(params) {
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
7
+ var xml = params.xml;
8
+ var parser = new HtmlTableExtractor_1.default();
9
+ var tables = parser.extractTables(xml, {
10
+ stripHtml: true,
11
+ tagsToExclude: ['sup'],
12
+ stripParenthesis: true,
13
+ removeEmptyColumns: false,
14
+ getHeaderRowIndex: function (data) {
15
+ return data.rows.findIndex(function (row) {
16
+ var isNotEmptyRow = row.some(function (cell) { return cell.html.replace(/<.*?>/g, '').replace(/&.*?;/g, '').replace(/\s/g, '').length > 0; });
17
+ return isNotEmptyRow;
18
+ });
19
+ },
20
+ });
21
+ var getTableHeadHtml = function (table) {
22
+ var _a;
23
+ var match = table.html.replace(/\n/g, '').match(/<b>.*?<\/b>/g);
24
+ var matches = Array.isArray(match) ? match : [];
25
+ return (_a = matches.find(function (match) { return match.includes('<a'); })) !== null && _a !== void 0 ? _a : null;
26
+ };
27
+ var tableCompany = tables.find(function (table) { return table.html.includes('cgi-bin/browse-edgar?action=getcompany') && getTableHeadHtml(table) !== null; });
28
+ var tableCompanyHead = tableCompany ? getTableHeadHtml(tableCompany) || '' : '';
29
+ var issuerCik = Number((_b = (_a = tableCompanyHead.split('</a>')[0]) === null || _a === void 0 ? void 0 : _a.split('>').pop()) === null || _b === void 0 ? void 0 : _b.trim()) || 0;
30
+ var issuerName = ((_d = (_c = tableCompanyHead.split('(')[0]) === null || _c === void 0 ? void 0 : _c.split('>').pop()) === null || _d === void 0 ? void 0 : _d.trim()) || '';
31
+ var cells = (_e = tableCompany === null || tableCompany === void 0 ? void 0 : tableCompany.rows.flat()) !== null && _e !== void 0 ? _e : [];
32
+ cells.find(function (cell) { return cell.html.toLowerCase().includes('<b'); });
33
+ var getHeaderRow = function (table) { return table.rows.find(function (row) { return row.some(function (cell) { return cell.isHeaderRowCell; }); }); };
34
+ var findTableWithCol = function (colTextLower) {
35
+ return tables.find(function (table) { var _a; return (_a = getHeaderRow(table)) === null || _a === void 0 ? void 0 : _a.some(function (cell) { return String(cell.valueParsed).toLowerCase().includes(colTextLower); }); });
36
+ };
37
+ var tableOwners = findTableWithCol('type of owner');
38
+ var tableTransactions = findTableWithCol('security name');
39
+ var stripHtml = function (html) {
40
+ return html
41
+ .replace(/<.*?>/g, '')
42
+ .replace(/&nbsp;/g, ' ')
43
+ .replace(/\n/g, ' ')
44
+ .replace(/\s+/, ' ')
45
+ .trim();
46
+ };
47
+ var ownerByCik = new Map();
48
+ var headerOwner = ['owner_name', 'filings', 'transaction_date', 'type_of_owner'];
49
+ var headerTransaction = [
50
+ 'acquisition_or_disposition',
51
+ 'transaction_date',
52
+ 'deemed_execution_date',
53
+ 'reporting_owner',
54
+ 'form',
55
+ 'transaction_type',
56
+ 'direct_or_indirect_ownership',
57
+ 'num_securities_transacted',
58
+ 'num_securities_following',
59
+ 'line_number',
60
+ 'owner_cik',
61
+ 'security_title',
62
+ ];
63
+ for (var _i = 0, _r = (_f = tableOwners === null || tableOwners === void 0 ? void 0 : tableOwners.rows) !== null && _f !== void 0 ? _f : []; _i < _r.length; _i++) {
64
+ var row = _r[_i];
65
+ if ((_g = row[0]) === null || _g === void 0 ? void 0 : _g.isHeaderRowCell)
66
+ continue;
67
+ var owner = {
68
+ ownerName: '',
69
+ ownerCik: 0,
70
+ ownerPosition: null,
71
+ isDirector: false,
72
+ isOfficer: false,
73
+ };
74
+ for (var _s = 0, row_1 = row; _s < row_1.length; _s++) {
75
+ var cell = row_1[_s];
76
+ var colName = headerOwner[cell.colIndex];
77
+ var htmlStripped = stripHtml(cell.html);
78
+ switch (colName) {
79
+ case 'owner_name':
80
+ owner.ownerName = htmlStripped.split('Current Name')[0];
81
+ break;
82
+ case 'filings':
83
+ owner.ownerCik = Number(cell.valueParsed || 0) || 0;
84
+ break;
85
+ case 'type_of_owner': {
86
+ var parts = htmlStripped.split(':');
87
+ owner.isDirector = (_h = parts[0]) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes('director');
88
+ owner.isOfficer = (_j = parts[0]) === null || _j === void 0 ? void 0 : _j.toLowerCase().includes('officer');
89
+ owner.ownerPosition = ((_k = parts[1]) === null || _k === void 0 ? void 0 : _k.trim()) || null;
90
+ break;
91
+ }
92
+ }
93
+ }
94
+ ownerByCik.set(owner.ownerCik, owner);
95
+ }
96
+ var transactions = [];
97
+ for (var _t = 0, _u = (_l = tableTransactions === null || tableTransactions === void 0 ? void 0 : tableTransactions.rows) !== null && _l !== void 0 ? _l : []; _t < _u.length; _t++) {
98
+ var row = _u[_t];
99
+ if ((_m = row[0]) === null || _m === void 0 ? void 0 : _m.isHeaderRowCell)
100
+ continue;
101
+ var transaction = {
102
+ ownerName: '',
103
+ ownerCik: 0,
104
+ ownerPosition: null,
105
+ issuerCik: issuerCik,
106
+ issuerName: issuerName,
107
+ isDirector: false,
108
+ isOfficer: false,
109
+ /** true = buy, false = sell */
110
+ isAcquisition: false,
111
+ isDirectOwnership: false,
112
+ securityTitle: '',
113
+ transactionDate: '',
114
+ transactionCode: '',
115
+ transactionShares: 0,
116
+ sharesOwnedFollowingTransaction: 0,
117
+ lineNumber: 0,
118
+ deemedExecutionDate: '',
119
+ form: '',
120
+ accessionNumber: '',
121
+ };
122
+ for (var _v = 0, row_2 = row; _v < row_2.length; _v++) {
123
+ var cell = row_2[_v];
124
+ var colName = headerTransaction[cell.colIndex];
125
+ var htmlStripped = stripHtml(cell.html);
126
+ switch (colName) {
127
+ case 'acquisition_or_disposition':
128
+ transaction.isAcquisition = String(cell.valueParsed).toLowerCase() === 'a';
129
+ break;
130
+ case 'transaction_date':
131
+ transaction.transactionDate = htmlStripped;
132
+ break;
133
+ case 'deemed_execution_date':
134
+ transaction.deemedExecutionDate = htmlStripped;
135
+ break;
136
+ case 'reporting_owner':
137
+ break;
138
+ case 'form': {
139
+ var url = (_p = (_o = cell.html.match(/href="([^"]+)"/)) === null || _o === void 0 ? void 0 : _o[1]) !== null && _p !== void 0 ? _p : '';
140
+ transaction.accessionNumber = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('-'));
141
+ transaction.form = htmlStripped;
142
+ break;
143
+ }
144
+ case 'transaction_type':
145
+ transaction.transactionCode = htmlStripped.trim()[0];
146
+ break;
147
+ case 'direct_or_indirect_ownership':
148
+ transaction.isDirectOwnership = htmlStripped.toLowerCase().includes('d');
149
+ break;
150
+ case 'num_securities_transacted':
151
+ transaction.transactionShares = Number(cell.valueParsed) || 0;
152
+ break;
153
+ case 'num_securities_following':
154
+ transaction.sharesOwnedFollowingTransaction = Number(cell.valueParsed) || 0;
155
+ break;
156
+ case 'line_number':
157
+ transaction.lineNumber = Number(cell.valueParsed) || 0;
158
+ break;
159
+ case 'owner_cik': {
160
+ var owner = ownerByCik.get(Number(cell.valueParsed) || 0);
161
+ if (owner) {
162
+ transaction.ownerName = owner.ownerName;
163
+ transaction.ownerCik = owner.ownerCik;
164
+ transaction.ownerPosition = owner.ownerPosition;
165
+ transaction.isDirector = owner.isDirector;
166
+ transaction.isOfficer = owner.isOfficer;
167
+ }
168
+ break;
169
+ }
170
+ case 'security_title':
171
+ transaction.securityTitle = htmlStripped;
172
+ break;
173
+ }
174
+ }
175
+ transactions.push(transaction);
176
+ }
177
+ var isSwitchedOwnerIssuer = (_q = tableTransactions === null || tableTransactions === void 0 ? void 0 : tableTransactions.rows) === null || _q === void 0 ? void 0 : _q.some(function (r) {
178
+ return r.some(function (c) { return String(c.valueParsed).toLowerCase() === 'issuer'; });
179
+ });
180
+ var owners = Array.from(ownerByCik.values());
181
+ var issuers = [{ issuerName: issuerName, issuerCik: issuerCik }];
182
+ // if searching by person, owner and issuer data will be switched
183
+ if (isSwitchedOwnerIssuer) {
184
+ issuers = owners.map(function (owner) { return ({
185
+ issuerName: owner.ownerName,
186
+ issuerCik: owner.ownerCik,
187
+ }); });
188
+ owners = [];
189
+ transactions.forEach(function (transaction) {
190
+ var issuerName = transaction.issuerName, issuerCik = transaction.issuerCik, ownerName = transaction.ownerName, ownerCik = transaction.ownerCik;
191
+ transaction.issuerCik = ownerCik;
192
+ transaction.issuerName = ownerName;
193
+ transaction.ownerCik = issuerCik;
194
+ transaction.ownerName = issuerName;
195
+ });
196
+ }
197
+ return { transactions: transactions, owners: owners, issuers: issuers };
198
+ }
199
+ exports.parseInsiderTransactions = parseInsiderTransactions;
@@ -0,0 +1,8 @@
1
+ import { FactItem, ReportRaw, XMLParams } from '../../../types';
2
+ import { GetDocumentXbrlParams } from '../../SecEdgarApi';
3
+ import { XbrlParseResult } from '../XBRLParser/XBRLParser';
4
+ export declare function parseXbrl(params: XMLParams & GetDocumentXbrlParams): XbrlParseResult & {
5
+ report: ReportRaw | null;
6
+ facts: FactItem[];
7
+ xml: string;
8
+ };
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.parseXbrl = void 0;
26
+ var constants_1 = require("../../../util/constants");
27
+ var XBRLParser_1 = require("../XBRLParser/XBRLParser");
28
+ function isWithinDays(params) {
29
+ var dateA = params.dateA, dateB = params.dateB, days = params.days;
30
+ var timeDiff = Math.abs(new Date(dateA).getTime() - new Date(dateB).getTime());
31
+ var daysDiff = timeDiff / (1000 * 3600 * 24);
32
+ return daysDiff < days;
33
+ }
34
+ function buildReportsFromFacts(params) {
35
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
36
+ var filing = params.filing, facts = params.facts, fiscalPeriod = params.fiscalPeriod, fiscalYear = params.fiscalYear, pathSeparator = params.pathSeparator, cikProp = params.cik;
37
+ var urlParts = (_a = filing === null || filing === void 0 ? void 0 : filing.url.split('/')) !== null && _a !== void 0 ? _a : [];
38
+ var cik = cikProp !== null && cikProp !== void 0 ? cikProp : urlParts[(_b = urlParts.indexOf('data')) !== null && _b !== void 0 ? _b : -1];
39
+ var reportFactValues = {
40
+ cik: Number(cik),
41
+ dateReport: (_c = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _c !== void 0 ? _c : '',
42
+ fiscalPeriod: fiscalPeriod,
43
+ fiscalYear: fiscalYear,
44
+ };
45
+ // if there is a split fact, make sure it's from the current fiscal year
46
+ var allowedMonthsPriorForSplit = fiscalPeriod === 'FY' ? 12 : 3;
47
+ var splitFact = facts.find(function (f) {
48
+ var _a;
49
+ return f.name.endsWith(constants_1.KEY_SPLIT) &&
50
+ isWithinDays({ dateA: f.filed, dateB: (_a = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _a !== void 0 ? _a : '', days: allowedMonthsPriorForSplit * 30 });
51
+ });
52
+ var reportFocus = {
53
+ cik: Number(cik !== null && cik !== void 0 ? cik : reportFactValues.cik),
54
+ dateFiled: (_d = filing === null || filing === void 0 ? void 0 : filing.filingDate) !== null && _d !== void 0 ? _d : '',
55
+ dateReport: String((_e = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _e !== void 0 ? _e : reportFactValues.dateReport),
56
+ fiscalPeriod: (fiscalPeriod !== null && fiscalPeriod !== void 0 ? fiscalPeriod : reportFactValues.fiscalPeriod),
57
+ fiscalYear: Number(fiscalYear !== null && fiscalYear !== void 0 ? fiscalYear : reportFactValues.fiscalYear),
58
+ splitDate: (_f = splitFact === null || splitFact === void 0 ? void 0 : splitFact.end) !== null && _f !== void 0 ? _f : null,
59
+ splitRatio: (splitFact === null || splitFact === void 0 ? void 0 : splitFact.value) ? Number(splitFact.value) : null,
60
+ url: (_g = filing === null || filing === void 0 ? void 0 : filing.url) !== null && _g !== void 0 ? _g : '',
61
+ };
62
+ var reportByDateRange = {};
63
+ var factByName = new Map();
64
+ var roundPlacesByName = new Map();
65
+ var scaleByName = new Map();
66
+ var isFocusFactByDateKey = new Map();
67
+ for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
68
+ var fact = facts_1[_i];
69
+ var dateKey = fact.start ? "".concat(fact.start, "_").concat(fact.end) : fact.end;
70
+ (_h = reportByDateRange[dateKey]) !== null && _h !== void 0 ? _h : (reportByDateRange[dateKey] = {
71
+ startDate: (_j = fact.start) !== null && _j !== void 0 ? _j : '',
72
+ endDate: fact.end,
73
+ });
74
+ var isFocusFact = (_k = isFocusFactByDateKey.get(dateKey)) !== null && _k !== void 0 ? _k : isWithinDays({ dateA: fact.end, dateB: reportFocus.dateReport, days: 45 });
75
+ isFocusFactByDateKey.set(dateKey, isFocusFact);
76
+ var el = fact;
77
+ var scale = Number((_l = el.scale) !== null && _l !== void 0 ? _l : 0) || 0;
78
+ var decimals = Number((_m = el.decimals) !== null && _m !== void 0 ? _m : 0) || 0;
79
+ var suffix = (_o = fact === null || fact === void 0 ? void 0 : fact.segments) === null || _o === void 0 ? void 0 : _o.map(function (_a) {
80
+ var dimension = _a.dimension, value = _a.value;
81
+ return "".concat(dimension).concat(pathSeparator).concat(value);
82
+ }).join(pathSeparator);
83
+ var nameKey = suffix ? "".concat(fact.name).concat(pathSeparator).concat(suffix) : fact.name;
84
+ var roundPlaces = scale + decimals;
85
+ var prevFactKey = "".concat(nameKey, "-").concat(dateKey);
86
+ var prevFact = factByName.get(prevFactKey);
87
+ var hasValue = Boolean(fact.value);
88
+ var hadValue = Boolean(prevFact === null || prevFact === void 0 ? void 0 : prevFact.value);
89
+ if (hasValue && hadValue && fact.value !== (prevFact === null || prevFact === void 0 ? void 0 : prevFact.value)) {
90
+ var prevRounding = roundPlacesByName.get(prevFactKey);
91
+ var prevScale = scaleByName.get(prevFactKey);
92
+ var prevFact_1 = factByName.get(prevFactKey);
93
+ var prevUnit = (_q = (_p = prevFact_1 === null || prevFact_1 === void 0 ? void 0 : prevFact_1.unit) === null || _p === void 0 ? void 0 : _p.split('_').pop()) === null || _q === void 0 ? void 0 : _q.toLowerCase();
94
+ var unit = (_s = (_r = fact.unit) === null || _r === void 0 ? void 0 : _r.split('_').pop()) === null || _s === void 0 ? void 0 : _s.toLowerCase();
95
+ var shouldSkip = [
96
+ (prevUnit === null || prevUnit === void 0 ? void 0 : prevUnit.length) === 3 && (unit === null || unit === void 0 ? void 0 : unit.length) === 3 && prevUnit !== unit && prevUnit === 'usd',
97
+ (prevRounding !== null && prevRounding !== void 0 ? prevRounding : 0) < roundPlaces,
98
+ (prevScale !== null && prevScale !== void 0 ? prevScale : 0) < scale,
99
+ (prevRounding !== null && prevRounding !== void 0 ? prevRounding : 0) === roundPlaces && (prevScale !== null && prevScale !== void 0 ? prevScale : 0) === scale && prevUnit === unit,
100
+ ].some(Boolean);
101
+ if (shouldSkip)
102
+ continue;
103
+ }
104
+ roundPlacesByName.set(prevFactKey, roundPlaces);
105
+ scaleByName.set(prevFactKey, scale);
106
+ factByName.set(prevFactKey, fact);
107
+ reportByDateRange[dateKey][nameKey] = fact.value;
108
+ if (isFocusFact) {
109
+ reportFocus[nameKey] = fact.value;
110
+ }
111
+ }
112
+ return { reportFocus: reportFocus, reportByDateRange: reportByDateRange, factsFiltered: Array.from(factByName.values()) };
113
+ }
114
+ function parseXbrl(params) {
115
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
116
+ var parser = new XBRLParser_1.default();
117
+ var xml = params.xml, _k = params.includeReport, includeReport = _k === void 0 ? true : _k, options = __rest(params, ["xml", "includeReport"]);
118
+ var response = parser.parse(xml, options);
119
+ var _l = (_b = (_a = response.instance) === null || _a === void 0 ? void 0 : _a.xbrl) !== null && _b !== void 0 ? _b : {}, _m = _l.contexts, contexts = _m === void 0 ? [] : _m, _o = _l.factElements, factElements = _o === void 0 ? [] : _o;
120
+ var contextById = new Map();
121
+ contexts.forEach(function (context) { return contextById.set(context.id, context); });
122
+ var cik = response.header.cik;
123
+ var accessionNumber = response.header.accessionNumber;
124
+ var accessionNumberNoHyphens = accessionNumber.replace(/-/g, '');
125
+ var facts = [];
126
+ for (var _i = 0, factElements_1 = factElements; _i < factElements_1.length; _i++) {
127
+ var fact = factElements_1[_i];
128
+ var context = contextById.get(fact.contextRef);
129
+ var end = (_d = (_c = context === null || context === void 0 ? void 0 : context.period.endDate) !== null && _c !== void 0 ? _c : context === null || context === void 0 ? void 0 : context.period.instant) !== null && _d !== void 0 ? _d : '';
130
+ var start = context === null || context === void 0 ? void 0 : context.period.startDate;
131
+ var factParsed = {
132
+ cik: cik,
133
+ end: end,
134
+ filed: response.header.filingDate,
135
+ name: fact.name,
136
+ unit: (_e = fact.unitRef) !== null && _e !== void 0 ? _e : 'pure',
137
+ value: isNaN(Number(fact.text)) ? String(fact.text) : Number(fact.text),
138
+ accn: accessionNumber,
139
+ form: response.header.form,
140
+ segments: (_f = context === null || context === void 0 ? void 0 : context.entity.segment) !== null && _f !== void 0 ? _f : [],
141
+ start: start,
142
+ };
143
+ if (factParsed.decimals) {
144
+ factParsed.decimals = Number(fact.decimals);
145
+ }
146
+ if (fact.scale) {
147
+ factParsed.scale = Number(fact.scale);
148
+ }
149
+ facts.push(factParsed);
150
+ }
151
+ var factsForBuilder = includeReport ? facts : [];
152
+ var _p = buildReportsFromFacts({
153
+ facts: factsForBuilder,
154
+ pathSeparator: '>',
155
+ fiscalPeriod: (_g = factsForBuilder.find(function (f) { return f.name === 'dei:DocumentFiscalPeriodFocus'; })) === null || _g === void 0 ? void 0 : _g.value,
156
+ fiscalYear: Number((_j = (_h = factsForBuilder.find(function (f) { return f.name === 'dei:DocumentFiscalYearFocus'; })) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0),
157
+ cik: response.header.cik,
158
+ filing: {
159
+ acceptanceDateTime: response.header.acceptanceDatetime,
160
+ accessionNumber: accessionNumber,
161
+ act: response.header.act,
162
+ fileNumber: response.header.fileNumber,
163
+ filingDate: response.header.filingDate,
164
+ form: response.header.form,
165
+ filmNumber: response.header.filmNumber,
166
+ isInlineXBRL: 1,
167
+ isXBRL: 1,
168
+ items: '',
169
+ primaryDocDescription: '',
170
+ primaryDocument: '',
171
+ reportDate: response.header.reportDate,
172
+ size: 1,
173
+ url: "https://www.sec.gov/Archives/edgar/data/".concat(cik, "/").concat(accessionNumberNoHyphens, "/").concat(accessionNumber, ".txt"),
174
+ urlPrimaryDocument: '',
175
+ },
176
+ }), factsFiltered = _p.factsFiltered, reportFocus = _p.reportFocus;
177
+ return __assign(__assign({}, response), { facts: factsFiltered, report: factsFiltered.length > 0 ? reportFocus : null, xml: xml });
178
+ }
179
+ exports.parseXbrl = parseXbrl;
@@ -0,0 +1,45 @@
1
+ export interface Cell {
2
+ attributes: string;
3
+ rowSpan: number;
4
+ colSpan: number;
5
+ rowIndex: number;
6
+ colIndex: number;
7
+ tableCellIndex: number;
8
+ html: string;
9
+ isHeaderRowCell: boolean;
10
+ isBodyTitleRowCell: boolean;
11
+ valueParsed: string | number | null;
12
+ headerCol: string | null;
13
+ headerRowIndex: number | null;
14
+ }
15
+ export interface TableHTMLData {
16
+ tableIndex: number;
17
+ parentTableIndex: number | null;
18
+ childTableIndexes: number[];
19
+ positionStart: number;
20
+ positionEnd: number;
21
+ htmlBefore: string;
22
+ html: string;
23
+ rows: Cell[][];
24
+ }
25
+ interface ParseOptions {
26
+ tagsToExclude?: string[];
27
+ stripParenthesis?: boolean;
28
+ removeEmptyColumns?: boolean;
29
+ stripHtml?: boolean;
30
+ getHeaderRowIndex?: (data: {
31
+ rows: Omit<Cell, 'headerRowIndex' | 'isHeaderRowCell' | 'isBodyRowCell' | 'headerCol'>[][];
32
+ table: TableHTMLData;
33
+ }) => number;
34
+ }
35
+ export default class HtmlTableExtractor {
36
+ extractTables(html: string, options?: ParseOptions): TableHTMLData[];
37
+ mergeHeaderRows(tables: TableHTMLData[]): void;
38
+ removeEmptyColumns(tables: TableHTMLData[]): TableHTMLData[];
39
+ private addTableCells;
40
+ private addMissingNameCol;
41
+ private addTableCellValues;
42
+ stripHtml(str: string, options?: Omit<ParseOptions, 'stripHtml' | 'stripParenthesis'>): string;
43
+ parseValue(str: string | number | null, options?: ParseOptions): string | number | null;
44
+ }
45
+ export {};