sec-edgar-api 0.3.3 → 0.4.0

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 (78) hide show
  1. package/build/services/Client/Client.d.ts +1 -0
  2. package/build/services/DocumentParser/DocumentParser.d.ts +18 -1
  3. package/build/services/DocumentParser/DocumentParser.js +17 -2
  4. package/build/services/DocumentParser/DocumentXmlSplitter.d.ts +17 -0
  5. package/build/services/DocumentParser/DocumentXmlSplitter.js +38 -0
  6. package/build/services/DocumentParser/ObjectUtil.d.ts +20 -0
  7. package/build/services/DocumentParser/ObjectUtil.js +60 -0
  8. package/build/services/DocumentParser/XBRLParser/HeaderParser.d.ts +38 -0
  9. package/build/services/DocumentParser/XBRLParser/HeaderParser.js +138 -0
  10. package/build/services/DocumentParser/XBRLParser/InstanceParser.d.ts +6 -0
  11. package/build/services/DocumentParser/XBRLParser/InstanceParser.js +107 -0
  12. package/build/services/DocumentParser/XBRLParser/LinkbaseParser.d.ts +13 -0
  13. package/build/services/DocumentParser/XBRLParser/LinkbaseParser.js +99 -0
  14. package/build/services/DocumentParser/XBRLParser/SchemaParser.d.ts +11 -0
  15. package/build/services/DocumentParser/XBRLParser/SchemaParser.js +144 -0
  16. package/build/services/DocumentParser/XBRLParser/XBRLParser.d.ts +34 -0
  17. package/build/services/DocumentParser/XBRLParser/XBRLParser.js +64 -0
  18. package/build/services/DocumentParser/XBRLParser/util-type.d.ts +15 -0
  19. package/build/services/DocumentParser/XBRLParser/util-type.js +34 -0
  20. package/build/services/DocumentParser/XMLNode/XMLNode.js +2 -2
  21. package/build/services/DocumentParser/XMLParser.d.ts +9 -38
  22. package/build/services/DocumentParser/XMLParser.js +88 -283
  23. package/build/services/DocumentParser/XMLParserLegacy.d.ts +43 -0
  24. package/build/services/DocumentParser/XMLParserLegacy.js +308 -0
  25. package/build/services/DocumentParser/parsers/index.d.ts +10 -0
  26. package/build/services/DocumentParser/parsers/index.js +10 -0
  27. package/build/services/DocumentParser/parsers/parse-companies.d.ts +5 -0
  28. package/build/services/DocumentParser/parsers/parse-companies.js +52 -0
  29. package/build/services/DocumentParser/parsers/parse-current-filings-daily.js +8 -8
  30. package/build/services/DocumentParser/parsers/parse-current-filings-xbrl.d.ts +2 -0
  31. package/build/services/DocumentParser/parsers/parse-current-filings-xbrl.js +104 -0
  32. package/build/services/DocumentParser/parsers/parse-current-filings.d.ts +2 -0
  33. package/build/services/DocumentParser/parsers/parse-current-filings.js +76 -0
  34. package/build/services/DocumentParser/parsers/parse-form-10k.d.ts +1 -1
  35. package/build/services/DocumentParser/parsers/parse-form-10k.js +2 -2
  36. package/build/services/DocumentParser/parsers/parse-form-13g.d.ts +1 -1
  37. package/build/services/DocumentParser/parsers/parse-form-13g.js +2 -2
  38. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +1 -1
  39. package/build/services/DocumentParser/parsers/parse-form-4.js +6 -4
  40. package/build/services/DocumentParser/parsers/parse-form-def14a.d.ts +1 -1
  41. package/build/services/DocumentParser/parsers/parse-form-def14a.js +2 -2
  42. package/build/services/DocumentParser/parsers/parse-insider-transaction.d.ts +7 -0
  43. package/build/services/DocumentParser/parsers/parse-insider-transaction.js +199 -0
  44. package/build/services/DocumentParser/parsers/parse-xbrl.d.ts +8 -0
  45. package/build/services/DocumentParser/parsers/parse-xbrl.js +171 -0
  46. package/build/services/HtmlTableExtractor/HtmlTableExtractor.d.ts +45 -0
  47. package/build/services/HtmlTableExtractor/HtmlTableExtractor.js +430 -0
  48. package/build/services/HtmlTableExtractor/index.d.ts +2 -0
  49. package/build/services/HtmlTableExtractor/index.js +4 -0
  50. package/build/services/ReportParser/ReportParser.d.ts +1 -1
  51. package/build/services/ReportParser/ReportWrapper.js +1 -1
  52. package/build/services/ReportRawBuilder/FactFiscalCalculator.d.ts +0 -1
  53. package/build/services/ReportRawBuilder/FactFiscalCalculator.js +1 -1
  54. package/build/services/ReportRawBuilder/FactGrouper.d.ts +1 -0
  55. package/build/services/ReportRawBuilder/FactGrouper.js +21 -13
  56. package/build/services/ReportRawBuilder/FactSplitAdjuster.js +17 -7
  57. package/build/services/ReportRawBuilder/ReportRawBuilder.d.ts +1 -0
  58. package/build/services/ReportRawBuilder/ReportRawBuilder.js +20 -15
  59. package/build/services/SecEdgarApi/FilingMapper.d.ts +4 -0
  60. package/build/services/SecEdgarApi/FilingMapper.js +37 -0
  61. package/build/services/SecEdgarApi/RequestWrapper.d.ts +2 -0
  62. package/build/services/SecEdgarApi/RequestWrapper.js +6 -4
  63. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +66 -2
  64. package/build/services/SecEdgarApi/SecEdgarApi.js +236 -71
  65. package/build/services/SecEdgarApi/Throttler.d.ts +9 -8
  66. package/build/types/common.type.d.ts +9 -9
  67. package/build/types/company-search.type.d.ts +5 -0
  68. package/build/types/company-search.type.js +2 -0
  69. package/build/types/current-filings.type.d.ts +57 -0
  70. package/build/types/current-filings.type.js +2 -0
  71. package/build/types/index.d.ts +3 -0
  72. package/build/types/index.js +3 -0
  73. package/build/types/insider-transaction.type.d.ts +32 -0
  74. package/build/types/insider-transaction.type.js +2 -0
  75. package/build/types/parsed-filings.type.d.ts +3 -3
  76. package/build/types/xbrl.type.d.ts +155 -0
  77. package/build/types/xbrl.type.js +2 -0
  78. package/package.json +8 -3
@@ -1,5 +1,5 @@
1
1
  import { Form13GData, XMLParams } from '../../../types';
2
- import XMLParser from '../XMLParser';
2
+ import XMLParser from '../XMLParserLegacy';
3
3
  /**
4
4
  * Form SC 13G - Institutional Holders
5
5
  *
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseForm13g = void 0;
4
- var XMLParser_1 = require("../XMLParser");
4
+ var XMLParserLegacy_1 = require("../XMLParserLegacy");
5
5
  /**
6
6
  * Form SC 13G - Institutional Holders
7
7
  *
@@ -9,7 +9,7 @@ var XMLParser_1 = require("../XMLParser");
9
9
  */
10
10
  function parseForm13g(params, xmlParser) {
11
11
  var _a, _b, _c, _d;
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 });
15
15
  var holders = [];
@@ -1,5 +1,5 @@
1
1
  import { Form4Data, XMLParams } from '../../../types';
2
- import XMLParser from '../XMLParser';
2
+ import XMLParser from '../XMLParserLegacy';
3
3
  /**
4
4
  * Form 4 - Insider Transactions
5
5
  *
@@ -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) {
@@ -154,10 +154,11 @@ function parseForm4(params, xmlParser) {
154
154
  continue;
155
155
  case 'price':
156
156
  case 'shares':
157
- case 'sharesEnding':
157
+ case 'sharesEnding': {
158
158
  var valueNum = Number(text.replace(/,/g, ''));
159
159
  transaction[colName] = text === '' || isNaN(valueNum) ? null : valueNum;
160
160
  continue;
161
+ }
161
162
  default:
162
163
  transaction[colName] = text;
163
164
  }
@@ -203,12 +204,13 @@ function parseForm4(params, xmlParser) {
203
204
  case 'shares':
204
205
  case 'sharesUnderlying':
205
206
  case 'priceExcercised':
206
- case 'sharesEnding':
207
+ case 'sharesEnding': {
207
208
  if (colName === 'shares' && transaction.shares !== null)
208
209
  continue;
209
210
  var valueNum = Number(text.replace(/,/g, ''));
210
211
  transaction[colName] = text === '' || isNaN(valueNum) ? null : valueNum;
211
212
  continue;
213
+ }
212
214
  default:
213
215
  transaction[colName] = text;
214
216
  }
@@ -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 { ParseXbrlOptions, XbrlParseResult } from '../XBRLParser/XBRLParser';
3
+ export declare function parseXbrl(params: XMLParams & ParseXbrlOptions & {
4
+ includeReport?: boolean;
5
+ }): XbrlParseResult & {
6
+ report: ReportRaw | null;
7
+ facts: FactItem[];
8
+ };
@@ -0,0 +1,171 @@
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 XBRLParser_1 = require("../XBRLParser/XBRLParser");
27
+ function isWithinDays(params) {
28
+ var dateA = params.dateA, dateB = params.dateB, days = params.days;
29
+ var timeDiff = Math.abs(new Date(dateA).getTime() - new Date(dateB).getTime());
30
+ var daysDiff = timeDiff / (1000 * 3600 * 24);
31
+ return daysDiff < days;
32
+ }
33
+ function buildReportsFromFacts(params) {
34
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
35
+ var filing = params.filing, facts = params.facts, fiscalPeriod = params.fiscalPeriod, fiscalYear = params.fiscalYear, pathSeparator = params.pathSeparator, cikProp = params.cik;
36
+ var urlParts = (_a = filing === null || filing === void 0 ? void 0 : filing.url.split('/')) !== null && _a !== void 0 ? _a : [];
37
+ var cik = cikProp !== null && cikProp !== void 0 ? cikProp : urlParts[(_b = urlParts.indexOf('data')) !== null && _b !== void 0 ? _b : -1];
38
+ var reportFactValues = {
39
+ cik: Number(cik),
40
+ dateReport: (_c = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _c !== void 0 ? _c : '',
41
+ fiscalPeriod: fiscalPeriod,
42
+ fiscalYear: fiscalYear,
43
+ };
44
+ var reportFocus = {
45
+ cik: Number(cik !== null && cik !== void 0 ? cik : reportFactValues.cik),
46
+ dateFiled: (_d = filing === null || filing === void 0 ? void 0 : filing.filingDate) !== null && _d !== void 0 ? _d : '',
47
+ dateReport: String((_e = filing === null || filing === void 0 ? void 0 : filing.reportDate) !== null && _e !== void 0 ? _e : reportFactValues.dateReport),
48
+ fiscalPeriod: (fiscalPeriod !== null && fiscalPeriod !== void 0 ? fiscalPeriod : reportFactValues.fiscalPeriod),
49
+ fiscalYear: Number(fiscalYear !== null && fiscalYear !== void 0 ? fiscalYear : reportFactValues.fiscalYear),
50
+ splitDate: null,
51
+ splitRatio: null,
52
+ url: (_f = filing === null || filing === void 0 ? void 0 : filing.url) !== null && _f !== void 0 ? _f : '',
53
+ };
54
+ var reportByDateRange = {};
55
+ var factByName = new Map();
56
+ var roundPlacesByName = new Map();
57
+ var scaleByName = new Map();
58
+ var isFocusFactByDateKey = new Map();
59
+ for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
60
+ var fact = facts_1[_i];
61
+ var dateKey = fact.start ? "".concat(fact.start, "_").concat(fact.end) : fact.end;
62
+ (_g = reportByDateRange[dateKey]) !== null && _g !== void 0 ? _g : (reportByDateRange[dateKey] = {
63
+ startDate: (_h = fact.start) !== null && _h !== void 0 ? _h : '',
64
+ endDate: fact.end,
65
+ });
66
+ var isFocusFact = (_j = isFocusFactByDateKey.get(dateKey)) !== null && _j !== void 0 ? _j : isWithinDays({ dateA: fact.end, dateB: reportFocus.dateReport, days: 45 });
67
+ isFocusFactByDateKey.set(dateKey, isFocusFact);
68
+ var el = fact;
69
+ var scale = Number((_k = el.scale) !== null && _k !== void 0 ? _k : 0) || 0;
70
+ var decimals = Number((_l = el.decimals) !== null && _l !== void 0 ? _l : 0) || 0;
71
+ var suffix = (_m = fact === null || fact === void 0 ? void 0 : fact.segments) === null || _m === void 0 ? void 0 : _m.map(function (_a) {
72
+ var dimension = _a.dimension, value = _a.value;
73
+ return "".concat(dimension).concat(pathSeparator).concat(value);
74
+ }).join(pathSeparator);
75
+ var nameKey = suffix ? "".concat(fact.name).concat(pathSeparator).concat(suffix) : fact.name;
76
+ var roundPlaces = scale + decimals;
77
+ var prevFactKey = "".concat(nameKey, "-").concat(dateKey);
78
+ var prevFact = factByName.get(prevFactKey);
79
+ var hasValue = Boolean(fact.value);
80
+ var hadValue = Boolean(prevFact === null || prevFact === void 0 ? void 0 : prevFact.value);
81
+ if (hasValue && hadValue && fact.value !== (prevFact === null || prevFact === void 0 ? void 0 : prevFact.value)) {
82
+ var prevRounding = roundPlacesByName.get(prevFactKey);
83
+ var prevScale = scaleByName.get(prevFactKey);
84
+ var prevFact_1 = factByName.get(prevFactKey);
85
+ var prevUnit = (_p = (_o = prevFact_1 === null || prevFact_1 === void 0 ? void 0 : prevFact_1.unit) === null || _o === void 0 ? void 0 : _o.split('_').pop()) === null || _p === void 0 ? void 0 : _p.toLowerCase();
86
+ var unit = (_r = (_q = fact.unit) === null || _q === void 0 ? void 0 : _q.split('_').pop()) === null || _r === void 0 ? void 0 : _r.toLowerCase();
87
+ var shouldSkip = [
88
+ (prevUnit === null || prevUnit === void 0 ? void 0 : prevUnit.length) === 3 && (unit === null || unit === void 0 ? void 0 : unit.length) === 3 && prevUnit !== unit && prevUnit === 'usd',
89
+ (prevRounding !== null && prevRounding !== void 0 ? prevRounding : 0) < roundPlaces,
90
+ (prevScale !== null && prevScale !== void 0 ? prevScale : 0) < scale,
91
+ (prevRounding !== null && prevRounding !== void 0 ? prevRounding : 0) === roundPlaces && (prevScale !== null && prevScale !== void 0 ? prevScale : 0) === scale && prevUnit === unit,
92
+ ].some(Boolean);
93
+ if (shouldSkip)
94
+ continue;
95
+ }
96
+ roundPlacesByName.set(prevFactKey, roundPlaces);
97
+ scaleByName.set(prevFactKey, scale);
98
+ factByName.set(prevFactKey, fact);
99
+ reportByDateRange[dateKey][nameKey] = fact.value;
100
+ if (isFocusFact) {
101
+ reportFocus[nameKey] = fact.value;
102
+ }
103
+ }
104
+ return { reportFocus: reportFocus, reportByDateRange: reportByDateRange, factsFiltered: Array.from(factByName.values()) };
105
+ }
106
+ function parseXbrl(params) {
107
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
108
+ var parser = new XBRLParser_1.default();
109
+ var xml = params.xml, _k = params.includeReport, includeReport = _k === void 0 ? true : _k, options = __rest(params, ["xml", "includeReport"]);
110
+ var response = parser.parse(xml, options);
111
+ 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;
112
+ var contextById = new Map();
113
+ contexts.forEach(function (context) { return contextById.set(context.id, context); });
114
+ var cik = response.header.cik;
115
+ var accessionNumber = response.header.accessionNumber;
116
+ var accessionNumberNoHyphens = accessionNumber.replace(/-/g, '');
117
+ var facts = [];
118
+ for (var _i = 0, factElements_1 = factElements; _i < factElements_1.length; _i++) {
119
+ var fact = factElements_1[_i];
120
+ var context = contextById.get(fact.contextRef);
121
+ 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 : '';
122
+ var start = context === null || context === void 0 ? void 0 : context.period.startDate;
123
+ var factParsed = {
124
+ cik: cik,
125
+ end: end,
126
+ filed: response.header.filingDate,
127
+ name: fact.name,
128
+ unit: (_e = fact.unitRef) !== null && _e !== void 0 ? _e : 'pure',
129
+ value: isNaN(Number(fact.text)) ? String(fact.text) : Number(fact.text),
130
+ accn: accessionNumber,
131
+ form: response.header.form,
132
+ segments: (_f = context === null || context === void 0 ? void 0 : context.entity.segment) !== null && _f !== void 0 ? _f : [],
133
+ start: start,
134
+ };
135
+ if (factParsed.decimals) {
136
+ factParsed.decimals = Number(fact.decimals);
137
+ }
138
+ if (fact.scale) {
139
+ factParsed.scale = Number(fact.scale);
140
+ }
141
+ facts.push(factParsed);
142
+ }
143
+ var factsForBuilder = includeReport ? facts : [];
144
+ var _p = buildReportsFromFacts({
145
+ facts: factsForBuilder,
146
+ pathSeparator: '>',
147
+ fiscalPeriod: (_g = factsForBuilder.find(function (f) { return f.name === 'dei:DocumentFiscalPeriodFocus'; })) === null || _g === void 0 ? void 0 : _g.value,
148
+ 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),
149
+ cik: response.header.cik,
150
+ filing: {
151
+ acceptanceDateTime: response.header.acceptanceDatetime,
152
+ accessionNumber: accessionNumber,
153
+ act: response.header.act,
154
+ fileNumber: response.header.fileNumber,
155
+ filingDate: response.header.filingDate,
156
+ form: response.header.form,
157
+ filmNumber: response.header.filmNumber,
158
+ isInlineXBRL: 1,
159
+ isXBRL: 1,
160
+ items: '',
161
+ primaryDocDescription: '',
162
+ primaryDocument: '',
163
+ reportDate: response.header.reportDate,
164
+ size: 1,
165
+ url: "https://www.sec.gov/Archives/edgar/data/".concat(cik, "/").concat(accessionNumberNoHyphens, "/").concat(accessionNumber, ".txt"),
166
+ urlPrimaryDocument: '',
167
+ },
168
+ }), factsFiltered = _p.factsFiltered, reportFocus = _p.reportFocus;
169
+ return __assign(__assign({}, response), { facts: factsFiltered, report: reportFocus });
170
+ }
171
+ 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 {};