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
@@ -0,0 +1,430 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var HtmlTableExtractor = /** @class */ (function () {
4
+ function HtmlTableExtractor() {
5
+ }
6
+ HtmlTableExtractor.prototype.extractTables = function (html, options) {
7
+ var _a, _b;
8
+ var tablesOpen = [];
9
+ var tableIndex = -1;
10
+ var htmlBefore = '';
11
+ var tablesData = [];
12
+ for (var i = 0; i < html.length; i++) {
13
+ var isTableStart = html.substring(i, i + 6).toLowerCase() === '<table';
14
+ var isTableEnd = html.substring(i - 7, i + 1).toLowerCase() === '</table>';
15
+ var parentTable = tablesOpen[tablesOpen.length - 1];
16
+ if (isTableStart) {
17
+ tableIndex++;
18
+ tablesOpen.push({
19
+ tableIndex: tableIndex,
20
+ parentTableIndex: (_a = parentTable === null || parentTable === void 0 ? void 0 : parentTable.tableIndex) !== null && _a !== void 0 ? _a : null,
21
+ childTableIndexes: [],
22
+ positionStart: i,
23
+ positionEnd: -1,
24
+ htmlBefore: htmlBefore,
25
+ html: '',
26
+ rows: [],
27
+ });
28
+ parentTable === null || parentTable === void 0 ? void 0 : parentTable.childTableIndexes.push(tableIndex);
29
+ htmlBefore = '';
30
+ }
31
+ if (tablesOpen.length === 0) {
32
+ htmlBefore += html[i];
33
+ }
34
+ for (var a = tablesOpen.length - 1; a >= 0; a--) {
35
+ tablesOpen[a].html += html[i];
36
+ }
37
+ if (isTableEnd && tablesOpen.length > 0) {
38
+ tablesOpen[tablesOpen.length - 1].positionEnd = i;
39
+ var tableData = tablesOpen.pop();
40
+ // tablesData[tableData.tableIndex] = tableData
41
+ tablesData.push(tableData);
42
+ }
43
+ }
44
+ this.addTableCells(tablesData);
45
+ this.addTableCellValues(tablesData, options);
46
+ this.addMissingNameCol(tablesData);
47
+ if ((_b = options === null || options === void 0 ? void 0 : options.removeEmptyColumns) !== null && _b !== void 0 ? _b : true) {
48
+ this.removeEmptyColumns(tablesData);
49
+ }
50
+ this.mergeHeaderRows(tablesData);
51
+ return tablesData.filter(Boolean);
52
+ };
53
+ HtmlTableExtractor.prototype.mergeHeaderRows = function (tables) {
54
+ var _a;
55
+ for (var _i = 0, tables_1 = tables; _i < tables_1.length; _i++) {
56
+ var table = tables_1[_i];
57
+ var bodyRowIndex = table.rows.findIndex(function (row) { return row.some(function (col) { return !col.isHeaderRowCell; }); });
58
+ var headerRowIndex = bodyRowIndex - 1;
59
+ var bodyRow = table.rows[bodyRowIndex];
60
+ var headerRow = table.rows[headerRowIndex];
61
+ if (!bodyRow || headerRowIndex < 0)
62
+ continue;
63
+ for (var i = 0; i < bodyRow.length; i++) {
64
+ var headerCol = headerRow[i];
65
+ var bodyCol = bodyRow[i];
66
+ if (!headerCol || !bodyCol)
67
+ continue;
68
+ headerCol.valueParsed = (_a = bodyCol.headerCol) !== null && _a !== void 0 ? _a : headerCol === null || headerCol === void 0 ? void 0 : headerCol.valueParsed;
69
+ }
70
+ }
71
+ };
72
+ HtmlTableExtractor.prototype.removeEmptyColumns = function (tables) {
73
+ var _a;
74
+ var _loop_1 = function (table) {
75
+ var emptyColumns = new Set();
76
+ var _loop_2 = function (c) {
77
+ var isAllEmpty = table.rows.every(function (row) { var _a, _b; return ((_a = row[c]) === null || _a === void 0 ? void 0 : _a.valueParsed) === null || ((_b = row[c]) === null || _b === void 0 ? void 0 : _b.isHeaderRowCell); });
78
+ if (isAllEmpty) {
79
+ emptyColumns.add(c);
80
+ }
81
+ };
82
+ for (var c = 0; c < ((_a = table.rows[0]) === null || _a === void 0 ? void 0 : _a.length); c++) {
83
+ _loop_2(c);
84
+ }
85
+ for (var r = 0; r < table.rows.length; r++) {
86
+ var row = table.rows[r];
87
+ table.rows[r] = row.filter(function (_, i) { return !emptyColumns.has(i); });
88
+ }
89
+ table.rows = table.rows.filter(function (row) { return row.some(function (col) { return col.valueParsed !== null; }); });
90
+ };
91
+ for (var _i = 0, tables_2 = tables; _i < tables_2.length; _i++) {
92
+ var table = tables_2[_i];
93
+ _loop_1(table);
94
+ }
95
+ return tables;
96
+ };
97
+ HtmlTableExtractor.prototype.addTableCells = function (tables) {
98
+ if (tables.length === 0)
99
+ return;
100
+ var tablesByIndex = new Map(tables.map(function (t) { return [t.tableIndex, t]; }));
101
+ tablesByIndex.forEach(function (table) {
102
+ var _a, _b;
103
+ var skipIndexMap = new Map(table.childTableIndexes.map(function (childIndex) {
104
+ var _a, _b;
105
+ var child = tablesByIndex.get(childIndex);
106
+ return [
107
+ ((_a = child === null || child === void 0 ? void 0 : child.positionStart) !== null && _a !== void 0 ? _a : 0) - table.positionStart,
108
+ ((_b = child === null || child === void 0 ? void 0 : child.positionEnd) !== null && _b !== void 0 ? _b : 0) - table.positionStart,
109
+ ];
110
+ }));
111
+ var grid = [];
112
+ var isInCell = false;
113
+ var isInCellAtts = false;
114
+ var cellAtts = '';
115
+ var cellHTML = '';
116
+ var rowIndex = -1;
117
+ var tableCellIndex = -1;
118
+ var createCell = function (html, atts) {
119
+ var _a, _b, _c, _d, _e, _f;
120
+ var attributePairs = atts
121
+ .toLowerCase()
122
+ .split(' ')
123
+ .map(function (att) { return att.split('='); });
124
+ var rowSpan = Number((_b = (_a = attributePairs.find(function (_a) {
125
+ var key = _a[0];
126
+ return key === 'rowspan';
127
+ })) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.replace(/[^0-9]/g, '')) || 1;
128
+ var colSpan = Number((_d = (_c = attributePairs.find(function (_a) {
129
+ var key = _a[0];
130
+ return key === 'colspan';
131
+ })) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.replace(/[^0-9]/g, '')) || 1;
132
+ var cell = {
133
+ attributes: atts.length > 4 ? atts.substring(4, atts.length - 1) : '',
134
+ html: html,
135
+ colSpan: colSpan,
136
+ rowSpan: rowSpan,
137
+ tableCellIndex: tableCellIndex,
138
+ rowIndex: rowIndex,
139
+ colIndex: -1,
140
+ isHeaderRowCell: false,
141
+ isBodyTitleRowCell: false,
142
+ valueParsed: null,
143
+ headerCol: null,
144
+ headerRowIndex: null,
145
+ };
146
+ // const hasCopies = cell.colSpan > 1 || cell.rowSpan > 1
147
+ var curRow = (_e = grid[rowIndex]) !== null && _e !== void 0 ? _e : [];
148
+ var nextEmptyCellIndex = curRow.findIndex(function (cell) { return !cell; });
149
+ var idxStart = nextEmptyCellIndex === -1 ? curRow.length : nextEmptyCellIndex;
150
+ for (var r = rowIndex; r < rowIndex + rowSpan; r++) {
151
+ grid[r] = (_f = grid[r]) !== null && _f !== void 0 ? _f : [];
152
+ for (var c = idxStart; c < idxStart + colSpan; c++) {
153
+ cell.colIndex = cell.colIndex > -1 ? cell.colIndex : c;
154
+ grid[r][c] = cell;
155
+ }
156
+ }
157
+ };
158
+ for (var i = 0; i < table.html.length; i++) {
159
+ var skipIndex = (_a = skipIndexMap.get(i)) !== null && _a !== void 0 ? _a : null;
160
+ if (skipIndex) {
161
+ cellHTML += table.html.substring(i, skipIndex + 1);
162
+ i = skipIndex;
163
+ continue;
164
+ }
165
+ var prev5Chars = table.html.substring(i - 4, i + 1).toLowerCase();
166
+ var next3Chars = table.html.substring(i, i + 3).toLowerCase();
167
+ var isCellAttsStart = ['<td', '<th'].includes(next3Chars);
168
+ var isSelfEnclosed = isInCellAtts && table.html[i - 1] === '/' && table.html[i] === '>';
169
+ var isCellAttsEnd = (isInCell && table.html[i] === '>') || isSelfEnclosed;
170
+ var isCellEnd = ['</td>', '</th>'].includes(prev5Chars);
171
+ var isRowStart = next3Chars === '<tr';
172
+ if (isRowStart) {
173
+ rowIndex++;
174
+ grid[rowIndex] = (_b = grid[rowIndex]) !== null && _b !== void 0 ? _b : [];
175
+ }
176
+ if (isCellAttsStart) {
177
+ tableCellIndex++;
178
+ isInCell = true;
179
+ isInCellAtts = true;
180
+ }
181
+ if (isInCellAtts) {
182
+ cellAtts += table.html[i];
183
+ }
184
+ if (isInCell) {
185
+ cellHTML += table.html[i];
186
+ }
187
+ if (isCellAttsEnd) {
188
+ isInCellAtts = false;
189
+ }
190
+ if (isCellEnd || isSelfEnclosed) {
191
+ isInCell = false;
192
+ isInCellAtts = false;
193
+ createCell(cellHTML, cellAtts);
194
+ cellHTML = '';
195
+ cellAtts = '';
196
+ }
197
+ }
198
+ table.rows = grid;
199
+ });
200
+ };
201
+ HtmlTableExtractor.prototype.addMissingNameCol = function (tables) {
202
+ var _a, _b;
203
+ var _loop_3 = function (table) {
204
+ var bodyIndex = table.rows.findIndex(function (row) { return row.some(function (col) { return !col.isHeaderRowCell; }); });
205
+ // get the first column index that has a value
206
+ var firstPopulatedColIndex = Infinity;
207
+ for (var i = bodyIndex; i < table.rows.length; i++) {
208
+ var row = table.rows[i];
209
+ if (!row)
210
+ continue;
211
+ var populatedIndex = row.findIndex(function (col) { return col === null || col === void 0 ? void 0 : col.valueParsed; });
212
+ var isFirstPopulatedIndex = populatedIndex > -1 && populatedIndex < firstPopulatedColIndex;
213
+ if (isFirstPopulatedIndex)
214
+ firstPopulatedColIndex = populatedIndex;
215
+ if (firstPopulatedColIndex === 0)
216
+ break;
217
+ }
218
+ var shouldAddName = table.rows.some(function (row) {
219
+ var firstCol = row[firstPopulatedColIndex];
220
+ var headerCol = firstCol === null || firstCol === void 0 ? void 0 : firstCol.headerCol;
221
+ // skip if the first column has a header col, or if there is no header row
222
+ if (!firstCol || headerCol || firstCol.headerRowIndex === null) {
223
+ return false;
224
+ }
225
+ // if the first col is a string, assume it's a name
226
+ return typeof (firstCol === null || firstCol === void 0 ? void 0 : firstCol.valueParsed) === 'string';
227
+ });
228
+ if (shouldAddName) {
229
+ for (var _c = 0, _d = table.rows; _c < _d.length; _c++) {
230
+ var row = _d[_c];
231
+ var col = row[firstPopulatedColIndex];
232
+ if (!col)
233
+ continue;
234
+ var isEmptyRow = row.every(function (col) { return (col === null || col === void 0 ? void 0 : col.valueParsed) === null; });
235
+ // for header rows, add to valueParsed, body rows, set headerCol
236
+ if (!isEmptyRow && col.isHeaderRowCell) {
237
+ col.valueParsed = (_a = col.valueParsed) !== null && _a !== void 0 ? _a : '[name]';
238
+ }
239
+ else if (!col.isHeaderRowCell) {
240
+ col.headerCol = (_b = col.headerCol) !== null && _b !== void 0 ? _b : '[name]';
241
+ }
242
+ }
243
+ }
244
+ };
245
+ for (var _i = 0, tables_3 = tables; _i < tables_3.length; _i++) {
246
+ var table = tables_3[_i];
247
+ _loop_3(table);
248
+ }
249
+ };
250
+ HtmlTableExtractor.prototype.addTableCellValues = function (tables, options) {
251
+ var _this = this;
252
+ var _a, _b;
253
+ var getHeaderRowIndexDefault = function (data) {
254
+ var rows = data.rows;
255
+ var bodyIndex = rows.findIndex(function (row, r) {
256
+ var _a;
257
+ var prevRow = (_a = rows[r - 1]) !== null && _a !== void 0 ? _a : [];
258
+ var hadUnderlines = prevRow.some(function (col) { return col.attributes.includes('border') && col.attributes.includes('bottom'); });
259
+ var hasUnderline = row.some(function (col) { return col.attributes.includes('border') && col.attributes.includes('bottom'); });
260
+ if (hadUnderlines && !hasUnderline) {
261
+ return true;
262
+ }
263
+ return row.some(function (col) {
264
+ var valueParsed = _this.parseValue(col.html, options);
265
+ var isNumber = typeof valueParsed === 'number';
266
+ var isYear = isNumber && valueParsed > 1900 && valueParsed < 2100;
267
+ var isCol = isNumber && !isYear;
268
+ return isCol;
269
+ });
270
+ });
271
+ return bodyIndex - 1;
272
+ };
273
+ var getHeaderRowIndexCb = (_a = options === null || options === void 0 ? void 0 : options.getHeaderRowIndex) !== null && _a !== void 0 ? _a : getHeaderRowIndexDefault;
274
+ var getHeaderRowIndex = function (data) {
275
+ return Math.max(getHeaderRowIndexCb(data), -1);
276
+ };
277
+ var getNextCell = function (row, colIndex) {
278
+ var startingCol = row[colIndex];
279
+ for (var i = colIndex; i < row.length; i++) {
280
+ if (!row[i])
281
+ continue;
282
+ if (row[i].tableCellIndex !== (startingCol === null || startingCol === void 0 ? void 0 : startingCol.tableCellIndex)) {
283
+ return row[i];
284
+ }
285
+ }
286
+ return null;
287
+ };
288
+ var completedCells = new Set();
289
+ var _loop_4 = function (table) {
290
+ var headerRowIndex = getHeaderRowIndex({ rows: table.rows, table: table });
291
+ var _loop_5 = function (rowIndex) {
292
+ var row = table.rows[rowIndex];
293
+ if (!row)
294
+ return "continue";
295
+ var countUniqueCells = new Set(row.map(function (c) { return c.tableCellIndex; })).size;
296
+ // skip titles in the middle of the body
297
+ var isBodyTitleRow = rowIndex > headerRowIndex && countUniqueCells === 1 && ((_b = row[0]) === null || _b === void 0 ? void 0 : _b.colSpan) > 0;
298
+ var isHeaderRow = rowIndex <= headerRowIndex;
299
+ var headerByIndex = new Map();
300
+ var getHeaderCol = function (c) {
301
+ var _a, _b, _c, _d, _e;
302
+ if (headerByIndex.has(c)) {
303
+ return (_a = headerByIndex.get(c)) !== null && _a !== void 0 ? _a : null;
304
+ }
305
+ if (isHeaderRow) {
306
+ return null;
307
+ }
308
+ for (var r = 0; r <= headerRowIndex; r++) {
309
+ var row_1 = table.rows[r];
310
+ if (!row_1)
311
+ continue;
312
+ for (var c_1 = 0; c_1 < row_1.length; c_1++) {
313
+ var col = (_c = (_b = row_1[c_1]) !== null && _b !== void 0 ? _b : row_1[c_1 - 1]) !== null && _c !== void 0 ? _c : row_1[c_1 + 1];
314
+ if (!col)
315
+ continue;
316
+ var headerCurrent = (_d = headerByIndex.get(c_1)) !== null && _d !== void 0 ? _d : '';
317
+ var value = headerCurrent.endsWith("".concat(col.valueParsed || ''))
318
+ ? headerCurrent
319
+ : "".concat(headerCurrent, " ").concat(col.valueParsed || '').trim();
320
+ headerByIndex.set(c_1, value);
321
+ }
322
+ }
323
+ return (_e = headerByIndex.get(c)) !== null && _e !== void 0 ? _e : null;
324
+ };
325
+ for (var colIndex = 0; colIndex < row.length; colIndex++) {
326
+ var cell = row[colIndex];
327
+ if (completedCells.has(cell) || !cell) {
328
+ continue;
329
+ }
330
+ cell.headerRowIndex = headerRowIndex > -1 ? headerRowIndex : null;
331
+ cell.isBodyTitleRowCell = isBodyTitleRow;
332
+ cell.isHeaderRowCell = isHeaderRow;
333
+ // sometimes there is a rogue percent sign that is not in a column, so we need to check the next column
334
+ var nextCell = getNextCell(row, colIndex);
335
+ // const isMissingPercentSign =
336
+ // nextCell?.html.includes('%') && this.parseValue(nextCell?.html) === null
337
+ var isMissingParenthesis = (nextCell === null || nextCell === void 0 ? void 0 : nextCell.html.includes(')')) && cell.html.includes('(') && !cell.html.includes(')');
338
+ var colValue = isMissingParenthesis ? "".concat(cell.html.trim(), ")") : cell.html.trim();
339
+ // colValue = isMissingPercentSign ? `${colValue}` : colValue
340
+ colValue = this_1.parseValue(colValue, options);
341
+ colValue = typeof colValue === 'string' ? colValue.replace(/\s+/g, ' ') : colValue;
342
+ // add parsed value
343
+ cell.valueParsed = colValue;
344
+ cell.headerCol = getHeaderCol(colIndex);
345
+ completedCells.add(cell);
346
+ }
347
+ };
348
+ for (var rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {
349
+ _loop_5(rowIndex);
350
+ }
351
+ };
352
+ var this_1 = this;
353
+ for (var _i = 0, tables_4 = tables; _i < tables_4.length; _i++) {
354
+ var table = tables_4[_i];
355
+ _loop_4(table);
356
+ }
357
+ };
358
+ HtmlTableExtractor.prototype.stripHtml = function (str, options) {
359
+ var _a = (options !== null && options !== void 0 ? options : {}).tagsToExclude, tagsToExclude = _a === void 0 ? [] : _a;
360
+ var strNew = str;
361
+ if (tagsToExclude.length > 0) {
362
+ strNew = '';
363
+ var _loop_6 = function (i) {
364
+ var char = str[i];
365
+ if (char !== '<') {
366
+ strNew += char;
367
+ return out_i_1 = i, "continue";
368
+ }
369
+ var matchedTag = tagsToExclude.find(function (tag) { return str.substring(i, i + tag.length + 1).toLowerCase() === "<".concat(tag); });
370
+ if (!matchedTag) {
371
+ strNew += char;
372
+ return out_i_1 = i, "continue";
373
+ }
374
+ var endTag = "</".concat(matchedTag, ">");
375
+ var endTagIndex = str.indexOf(endTag, i);
376
+ if (endTagIndex > -1) {
377
+ i = endTagIndex + endTag.length - 1;
378
+ }
379
+ out_i_1 = i;
380
+ };
381
+ var out_i_1;
382
+ for (var i = 0; i < str.length; i++) {
383
+ _loop_6(i);
384
+ i = out_i_1;
385
+ }
386
+ }
387
+ return strNew.replace(/<.*?>/gm, '');
388
+ };
389
+ HtmlTableExtractor.prototype.parseValue = function (str, options) {
390
+ var _a;
391
+ if (str === null)
392
+ return null;
393
+ if (typeof str === 'number')
394
+ return str;
395
+ var _b = options !== null && options !== void 0 ? options : {}, _c = _b.stripHtml, stripHtml = _c === void 0 ? true : _c, _d = _b.tagsToExclude, tagsToExclude = _d === void 0 ? [] : _d, _e = _b.stripParenthesis, stripParenthesis = _e === void 0 ? false : _e;
396
+ var strNew = stripHtml ? this.stripHtml(str, { tagsToExclude: tagsToExclude }) : str;
397
+ var text = strNew
398
+ .replace(/&#160;|&nbsp;|\n/g, ' ')
399
+ .replace(/&#174;|&#9744;/g, '')
400
+ .replace(/&#8211;|&#8212;|&#x2014;|&#151;/g, '-')
401
+ .replace(/&#8217;|&#8220;|&#8221;|&rsquo;/g, "'");
402
+ if (stripParenthesis) {
403
+ text = text.replace(/\(.*?\)/g, '');
404
+ }
405
+ text = text
406
+ .replace(/\s+/, ' ')
407
+ .replace(/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/g, ' ')
408
+ .trim();
409
+ if (str.replace(/&#8211;|&#8212;|&#x2014;/g, '-') === '-')
410
+ return '-';
411
+ if (text === '')
412
+ return null;
413
+ var colNum = text.replace(/,|\(|\)|%/g, '').trim();
414
+ if (colNum === '-' || colNum === '$')
415
+ return null;
416
+ colNum = colNum.replace(/-|\$/g, '');
417
+ var hasNumBeforeParenthesis = Boolean(/\d+\s*(?=\()/.test(text));
418
+ colNum = hasNumBeforeParenthesis ? (_a = colNum.split(' ')[0]) === null || _a === void 0 ? void 0 : _a.trim() : colNum;
419
+ if (!isNaN(Number(colNum))) {
420
+ if (text.includes('%'))
421
+ return text.replace(/[^a-zA-Z\d\s:]/g, '') === '' ? null : text;
422
+ return (text.trim().includes('(') && !hasNumBeforeParenthesis) || text.includes('-')
423
+ ? Number(colNum) * -1
424
+ : Number(colNum);
425
+ }
426
+ return text;
427
+ };
428
+ return HtmlTableExtractor;
429
+ }());
430
+ exports.default = HtmlTableExtractor;
@@ -0,0 +1,2 @@
1
+ import HtmlTableExtractor from './HtmlTableExtractor';
2
+ export default HtmlTableExtractor;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var HtmlTableExtractor_1 = require("./HtmlTableExtractor");
4
+ exports.default = HtmlTableExtractor_1.default;
@@ -8,7 +8,7 @@ interface ReportParserArgs {
8
8
  propertyResolver?: PropertyResolver;
9
9
  keyTranslator?: Record<string, string[]>;
10
10
  }
11
- type TranslateRawReportsCallback<T> = (report: T extends undefined ? ReportTranslated : Record<keyof T, string | number>, reportRaw: ReportRaw, keyTranslator: T) => any;
11
+ type TranslateRawReportsCallback<T> = (report: T extends undefined ? ReportTranslated : Record<keyof T, string | number>, reportRaw: ReportRaw, keyTranslator: T) => ReportTranslated | ReportRaw | Record<string, string | number | null>;
12
12
  /**
13
13
  * Takes company facts data from the SEC and translates them to reports as json objects.
14
14
  */
@@ -32,7 +32,7 @@ var ReportWrapper = /** @class */ (function (_super) {
32
32
  url: report.url,
33
33
  dateFiled: report.dateFiled,
34
34
  dateReport: report.dateReport,
35
- fiscalPeriod: (_a = report.fiscalPeriod) !== null && _a !== void 0 ? _a : '',
35
+ fiscalPeriod: ((_a = report.fiscalPeriod) !== null && _a !== void 0 ? _a : ''),
36
36
  fiscalYear: report.fiscalYear,
37
37
  splitRatio: null,
38
38
  splitDate: null,
@@ -20,7 +20,6 @@ export default class FactFiscalCalculator {
20
20
  add(fact: {
21
21
  end: string;
22
22
  filed: string;
23
- frame?: string;
24
23
  }): void;
25
24
  private getDaysBefore;
26
25
  setReportDates(params: SetReportDatesParams): void;
@@ -16,7 +16,7 @@ var FactFiscalCalculator = /** @class */ (function () {
16
16
  }
17
17
  FactFiscalCalculator.prototype.add = function (fact) {
18
18
  var _a, _b, _c;
19
- var end = fact.end, filed = fact.filed, frame = fact.frame;
19
+ var end = fact.end, filed = fact.filed;
20
20
  if (this.didResolve) {
21
21
  throw new Error('Cannot add fact after resolving');
22
22
  }
@@ -8,6 +8,7 @@ export default class FactGrouper {
8
8
  private preferFirstValue;
9
9
  private createFactGroup;
10
10
  private createGroupKey;
11
+ private toValue;
11
12
  /**
12
13
  * Map structure { 2022_Q3: { name: ... } }. NOTE: Does not include fiscal year report key.
13
14
  * All groups contain both trailing and period values, so use trailing from Q4 to get FY values.
@@ -28,14 +28,17 @@ var FactGrouper = /** @class */ (function () {
28
28
  var fiscalYear = params.fiscalYear, quarter = params.quarter, name = params.name;
29
29
  return "".concat(fiscalYear, "_").concat(quarter, "_").concat(name);
30
30
  };
31
+ FactGrouper.prototype.toValue = function (value) {
32
+ return !isNaN(value) ? Number(value) : value || null;
33
+ };
31
34
  /**
32
35
  * Map structure { 2022_Q3: { name: ... } }. NOTE: Does not include fiscal year report key.
33
36
  * All groups contain both trailing and period values, so use trailing from Q4 to get FY values.
34
37
  */
35
38
  FactGrouper.prototype.buildFactGroupsByReportKey = function (params) {
36
39
  var _this = this;
37
- var _a, _b, _c;
38
- var facts = params.facts, cik = params.cik, fiscalCalculator = params.fiscalCalculator, resolvePeriodValues = params.resolvePeriodValues, _d = params.generateMissingGroups, generateMissingGroups = _d === void 0 ? false : _d, splits = params.splits;
40
+ var _a, _b, _c, _d;
41
+ var facts = params.facts, cik = params.cik, fiscalCalculator = params.fiscalCalculator, resolvePeriodValues = params.resolvePeriodValues, _e = params.generateMissingGroups, generateMissingGroups = _e === void 0 ? false : _e, splits = params.splits;
39
42
  // min and max year will be used to sort the reports
40
43
  var minYear = 0;
41
44
  var maxYear = 9999;
@@ -48,8 +51,8 @@ var FactGrouper = /** @class */ (function () {
48
51
  // Create groups from facts.
49
52
  for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
50
53
  var fact = facts_1[_i];
51
- var _e = fiscalCalculator.getFiscalYearQuarter({ dateStr: fact.end }), quarter = _e.quarter, year = _e.year;
52
- var _f = (_a = fiscalCalculator.getDatesByYearQuarter({ quarter: quarter, year: year })) !== null && _a !== void 0 ? _a : {}, _g = _f.end, reportEnd = _g === void 0 ? '' : _g, _h = _f.filed, reportFiled = _h === void 0 ? '' : _h;
54
+ var _f = fiscalCalculator.getFiscalYearQuarter({ dateStr: fact.end }), quarter = _f.quarter, year = _f.year;
55
+ var _g = (_a = fiscalCalculator.getDatesByYearQuarter({ quarter: quarter, year: year })) !== null && _a !== void 0 ? _a : {}, _h = _g.end, reportEnd = _h === void 0 ? '' : _h, _j = _g.filed, reportFiled = _j === void 0 ? '' : _j;
53
56
  var groupKey = this.createGroupKey({ fiscalYear: year, quarter: quarter, name: fact.name });
54
57
  if (year < minYear)
55
58
  minYear = year;
@@ -59,7 +62,7 @@ var FactGrouper = /** @class */ (function () {
59
62
  var period = periodResolver.getPeriod(fact);
60
63
  var isPeriodFact = period <= 3;
61
64
  var isTrailingFact = period > 3 || (isPeriodFact && quarter === 1);
62
- var factValue = Number(fact.value);
65
+ var factValue = this.toValue(fact.value);
63
66
  // if no group exists, create from fact
64
67
  if (!factGroupByKey.has(groupKey)) {
65
68
  var group_1 = this.createFactGroup({
@@ -79,9 +82,12 @@ var FactGrouper = /** @class */ (function () {
79
82
  valuePeriodLast: isPeriodFact ? factValue : null,
80
83
  valueTrailingFirst: isTrailingFact ? factValue : null,
81
84
  valueTrailingLast: isTrailingFact ? factValue : null,
82
- values: [factValue],
85
+ values: [],
83
86
  facts: [fact],
84
87
  });
88
+ if (factValue !== null) {
89
+ group_1.values.push(factValue);
90
+ }
85
91
  accnByFiled.set(fact.filed, (_b = fact.accn) !== null && _b !== void 0 ? _b : '');
86
92
  unitByPropertyName.set(fact.name, fact.unit);
87
93
  factGroupByKey.set(groupKey, group_1);
@@ -94,11 +100,11 @@ var FactGrouper = /** @class */ (function () {
94
100
  group.endLast = fact.end > group.endLast ? fact.end : group.endLast;
95
101
  group.filedFirst = fact.filed < group.filedFirst ? fact.filed : group.filedFirst;
96
102
  group.filedLast = fact.filed > group.filedLast ? fact.filed : group.filedLast;
97
- if (!group.values.includes(factValue)) {
103
+ if (factValue !== null && !group.values.includes(factValue)) {
98
104
  group.values.push(factValue);
99
105
  }
100
- if (!group.accn && periodResolver.isOriginalFiling({ end: fact.end, filed: fact.filed })) {
101
- group.accn = (_c = fact.accn) !== null && _c !== void 0 ? _c : '';
106
+ if (periodResolver.isOriginalFiling({ end: fact.end, filed: fact.filed })) {
107
+ group.accn = (_d = (_c = fact.accn) !== null && _c !== void 0 ? _c : group.accn) !== null && _d !== void 0 ? _d : '';
102
108
  accnByFiled.set(fact.filed, group.accn);
103
109
  }
104
110
  if (isPeriodFact) {
@@ -139,24 +145,26 @@ var FactGrouper = /** @class */ (function () {
139
145
  var period = FactPeriodResolver_1.default.getPeriod(fact);
140
146
  return fact.value === preferredValueTrailing && (period > 3 || period === 0);
141
147
  });
142
- if (selectedFactPeriod) {
148
+ var valuePeriod = _this.toValue((_a = group.valueSplitAdjustedPeriod) !== null && _a !== void 0 ? _a : preferredValuePeriod);
149
+ var valueTrailing = _this.toValue((_b = group.valueSplitAdjustedTrailing) !== null && _b !== void 0 ? _b : preferredValueTrailing);
150
+ if (selectedFactPeriod && valuePeriod !== null) {
143
151
  periodResolver.add({
144
152
  end: selectedFactPeriod.end,
145
153
  filed: selectedFactPeriod.filed,
146
154
  name: selectedFactPeriod.name,
147
155
  quarter: group.quarter,
148
- value: Number((_a = group.valueSplitAdjustedPeriod) !== null && _a !== void 0 ? _a : preferredValuePeriod),
156
+ value: valuePeriod,
149
157
  year: group.fiscalYear,
150
158
  start: selectedFactPeriod.start,
151
159
  });
152
160
  }
153
- if (selectedFactTrailing) {
161
+ if (selectedFactTrailing && valueTrailing !== null) {
154
162
  periodResolver.add({
155
163
  end: selectedFactTrailing.end,
156
164
  filed: selectedFactTrailing.filed,
157
165
  name: selectedFactTrailing.name,
158
166
  quarter: group.quarter,
159
- value: Number((_b = group.valueSplitAdjustedTrailing) !== null && _b !== void 0 ? _b : preferredValueTrailing),
167
+ value: valueTrailing,
160
168
  year: group.fiscalYear,
161
169
  start: selectedFactTrailing.start,
162
170
  });
@@ -150,20 +150,30 @@ var FactSplitAdjuster = /** @class */ (function () {
150
150
  * Splits can be filed multiple times throughout different reports.
151
151
  */
152
152
  FactSplitAdjuster.prototype.didApplySplit = function (params) {
153
- var isShareRatio = params.isShareRatio, factGroup = params.factGroup, split = params.split, isTrailing = params.isTrailing, _a = params.useOppositePeriodFallback, useOppositePeriodFallback = _a === void 0 ? true : _a;
153
+ var _a;
154
+ var isShareRatio = params.isShareRatio, factGroup = params.factGroup, split = params.split, isTrailing = params.isTrailing, _b = params.useOppositePeriodFallback, useOppositePeriodFallback = _b === void 0 ? true : _b;
154
155
  var splitVal = split.splitRatio;
155
- if (!splitVal)
156
+ // string values are not adjusted
157
+ if (typeof ((_a = factGroup.valuePeriodFirst) !== null && _a !== void 0 ? _a : factGroup.valueTrailingFirst) === 'string') {
156
158
  return true;
157
- // these first two criteria will take care of the majority of cases...
159
+ }
160
+ // can't apply split values of 0 or null
161
+ if (!splitVal) {
162
+ return true;
163
+ }
164
+ // these two criteria will take care of the majority of cases where the fact was not filed in
165
+ // the window of the first and last filing of the split
158
166
  if (factGroup.filedFirst > split.filedLast) {
159
167
  return true;
160
168
  }
161
169
  if (factGroup.filedLast < split.filedFirst) {
162
170
  return false;
163
171
  }
172
+ // fact that is being used as the group value
164
173
  var resolvedFact = factGroup.facts.find(function (f) {
165
174
  return isTrailing ? f.value === factGroup.valueTrailingFirst : f.value === factGroup.valuePeriodFirst;
166
175
  });
176
+ // if resolved fact not found, try checking trailing or period (whichever is not the current one)
167
177
  if (!resolvedFact && useOppositePeriodFallback) {
168
178
  return this.didApplySplit(__assign(__assign({}, params), { isTrailing: !isTrailing, useOppositePeriodFallback: false }));
169
179
  }
@@ -185,10 +195,10 @@ var FactSplitAdjuster = /** @class */ (function () {
185
195
  return isAdjusted;
186
196
  }
187
197
  }
188
- if ((resolvedFact === null || resolvedFact === void 0 ? void 0 : resolvedFact.filed) > split.filedLast) {
198
+ if ((resolvedFact === null || resolvedFact === void 0 ? void 0 : resolvedFact.filed) && resolvedFact.filed > split.filedLast) {
189
199
  return true;
190
200
  }
191
- if ((resolvedFact === null || resolvedFact === void 0 ? void 0 : resolvedFact.filed) < split.filedFirst) {
201
+ if ((resolvedFact === null || resolvedFact === void 0 ? void 0 : resolvedFact.filed) && resolvedFact.filed < split.filedFirst) {
192
202
  return false;
193
203
  }
194
204
  // // if the filed date of the fact overlaps with the filed date of the split, try comparing the end dates
@@ -196,12 +206,12 @@ var FactSplitAdjuster = /** @class */ (function () {
196
206
  return false;
197
207
  }
198
208
  // if we still don't know, see if the split value puts us closer to the last known value or further
199
- if (factGroup.valuePeriodLast !== null) {
209
+ if (typeof factGroup.valuePeriodLast === 'number') {
200
210
  var val = this.getGroupValue(factGroup, isTrailing);
201
211
  var valueWithSplit = isShareRatio ? val / splitVal : val * splitVal;
202
212
  return Math.abs(factGroup.valuePeriodLast - val) < Math.abs(factGroup.valuePeriodLast - valueWithSplit);
203
213
  }
204
- if (factGroup.valueTrailingLast !== null) {
214
+ if (typeof factGroup.valueTrailingLast === 'number') {
205
215
  var val = this.getGroupValue(factGroup, isTrailing);
206
216
  var valueWithSplit = isShareRatio ? val / splitVal : val * splitVal;
207
217
  return Math.abs(factGroup.valueTrailingLast - val) < Math.abs(factGroup.valueTrailingLast - valueWithSplit);
@@ -31,6 +31,7 @@ export default class ReportRawBuilder {
31
31
  factGroupsByReportKey: Map<string, FactGroup[]>;
32
32
  fiscalCalculator: FactFiscalCalculator;
33
33
  splits?: SplitData[];
34
+ accessionByYearQuarter?: Map<string, string>;
34
35
  minYear: number;
35
36
  maxYear: number;
36
37
  cik: number;