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
@@ -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;
@@ -37,8 +37,8 @@ var FactGrouper = /** @class */ (function () {
37
37
  */
38
38
  FactGrouper.prototype.buildFactGroupsByReportKey = function (params) {
39
39
  var _this = this;
40
- var _a, _b, _c;
41
- 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;
42
42
  // min and max year will be used to sort the reports
43
43
  var minYear = 0;
44
44
  var maxYear = 9999;
@@ -51,8 +51,8 @@ var FactGrouper = /** @class */ (function () {
51
51
  // Create groups from facts.
52
52
  for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
53
53
  var fact = facts_1[_i];
54
- var _e = fiscalCalculator.getFiscalYearQuarter({ dateStr: fact.end }), quarter = _e.quarter, year = _e.year;
55
- 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;
56
56
  var groupKey = this.createGroupKey({ fiscalYear: year, quarter: quarter, name: fact.name });
57
57
  if (year < minYear)
58
58
  minYear = year;
@@ -103,8 +103,8 @@ var FactGrouper = /** @class */ (function () {
103
103
  if (factValue !== null && !group.values.includes(factValue)) {
104
104
  group.values.push(factValue);
105
105
  }
106
- if (!group.accn && periodResolver.isOriginalFiling({ end: fact.end, filed: fact.filed })) {
107
- 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 : '';
108
108
  accnByFiled.set(fact.filed, group.accn);
109
109
  }
110
110
  if (isPeriodFact) {
@@ -20,6 +20,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
20
20
  return to.concat(ar || Array.prototype.slice.call(from));
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
+ var constants_1 = require("../../util/constants");
23
24
  var FactPeriodResolver_1 = require("./FactPeriodResolver");
24
25
  /**
25
26
  * Splits can be filed multiple times throughout different reports. There is no clear
@@ -29,7 +30,7 @@ var FactPeriodResolver_1 = require("./FactPeriodResolver");
29
30
  */
30
31
  var FactSplitAdjuster = /** @class */ (function () {
31
32
  function FactSplitAdjuster() {
32
- this.keySplit = 'StockholdersEquityNoteStockSplitConversionRatio1';
33
+ this.keySplit = constants_1.KEY_SPLIT;
33
34
  this.preferFirstValue = true;
34
35
  }
35
36
  FactSplitAdjuster.prototype.getGroupValue = function (factGroup, isTrailing) {
@@ -53,11 +53,37 @@ export interface GetFactFrameParams {
53
53
  unit?: 'pure' | 'USD' | 'shares' | string;
54
54
  taxonomy?: 'us-gaap' | 'dei' | 'invest' | string;
55
55
  }
56
- export interface GetDocumentXMLParams {
57
- /** symbol or cik */
56
+ export interface GetInsiderTransactionsParams {
57
+ page: number;
58
58
  symbol: string | number;
59
- accessionNumber: string;
60
- primaryDocument: string;
59
+ itemsPerPage?: number;
60
+ isOwnerCik?: boolean;
61
+ }
62
+ export interface SearchCompaniesParams {
63
+ sic?: number;
64
+ /** Abbreviation of state: IL, CA, NY, etc... */
65
+ state?: string;
66
+ page: number;
67
+ itemsPerPage?: number;
68
+ /** Partial name of the company for search. */
69
+ company?: string;
70
+ companyMatch?: 'startsWith' | 'contains';
71
+ }
72
+ interface GetCurrentFilingsParams {
73
+ formType?: '4' | '3' | '10-Q' | '10-K' | 'SC 13G' | '13F-HR' | '8-K';
74
+ page?: number;
75
+ itemsPerPage?: number;
76
+ symbol?: string | number;
77
+ searchType?: 'include' | 'exclude' | 'only';
78
+ }
79
+ export interface GetDocumentXbrlParams {
80
+ url?: string;
81
+ symbol?: string | number;
82
+ accessionNumber?: string;
83
+ includeReport?: boolean;
84
+ includeInstance?: boolean;
85
+ includeLinkbases?: boolean;
86
+ includeSchema?: boolean;
61
87
  }
62
88
  /**
63
89
  * Gets reports from companies filed with the SEC
@@ -168,7 +194,8 @@ export default class SecEdgarApi {
168
194
  */
169
195
  getMutualFundList(): Promise<FieldDataResponse<'cik' | 'seriesId' | 'classId' | 'symbol'>>;
170
196
  /**
171
- * Gets a raw xml document string. the parameters are found in the submission list response.
197
+ * If url is provided, all other props are ignored. Otherwise, both accessionNumber
198
+ * and symbol (symbol or cik) are required. provide fileName if different from `${accessionNumber}.txt`
172
199
  *
173
200
  * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
174
201
  *
@@ -176,19 +203,32 @@ export default class SecEdgarApi {
176
203
  *
177
204
  * @see https://www.sec.gov/forms for a list of form types
178
205
  */
179
- getDocumentXML(params: GetDocumentXMLParams): Promise<string>;
206
+ getDocument(params: {
207
+ url?: string;
208
+ symbol?: string | number;
209
+ accessionNumber?: string;
210
+ fileName?: string;
211
+ }): Promise<string>;
180
212
  /**
181
- * Gets a raw xml document string. the url is found in the submission list response. (response.filings.recentTranslated.url)
182
- *
183
- * Some form types can be parsed using the DocumentParser such as form 4 (insider transactions) and form 13g (institutional holders)
213
+ * Fetches SEC document and parses XBRL data. If url is provided, symbol and accessionNumber are ignored.
184
214
  *
185
- * endpoint: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumber}/${primaryDocument}`
215
+ * Use "include" params to specify what to parse. If not provided, all data is parsed.
216
+ */
217
+ getDocumentXbrl(params: GetDocumentXbrlParams): Promise<import("../DocumentParser/XBRLParser/XBRLParser").XbrlParseResult & {
218
+ report: ReportRaw | null;
219
+ facts: import("../../types").FactItem[];
220
+ xml: string;
221
+ }>;
222
+ /**
223
+ * Builds a url for a document. If fileName is not provided, it defaults to `${accessionNumber}.txt`
186
224
  *
187
- * @see https://www.sec.gov/forms for a list of form types
225
+ * format: `https://www.sec.gov/Archives/edgar/data/${cik}/${accessionNumberNoHyphen)}/${fileNameAccessionFile}`
188
226
  */
189
- getDocumentXMLByUrl(params: {
190
- url: string;
191
- }): Promise<string>;
227
+ buildDocumentUrl(params: {
228
+ symbol: string | number;
229
+ accessionNumber: string;
230
+ fileName?: string;
231
+ }): string;
192
232
  /**
193
233
  * Used for getting insider transactions. extracts insider transaction urls from submission list response, and parses the xml doc.
194
234
  *
@@ -237,12 +277,13 @@ export default class SecEdgarApi {
237
277
  */
238
278
  createRequestProxyStatement(params: CreateRequestWrapperParams): SubmissionRequestWrapper<FormDef14aData>;
239
279
  /**
240
- * Gets list of latest filings.
280
+ * Gets list of filings for a day up to 5 days ago.
241
281
  *
242
282
  * @see https://www.sec.gov/edgar/searchedgar/currentevents
243
283
  */
244
284
  getCurrentFilingsDaily(params?: {
245
285
  formType?: DailyFilingFormType;
286
+ /** max 5 */
246
287
  lookbackDays?: number;
247
288
  }): Promise<{
248
289
  date: string;
@@ -256,5 +297,31 @@ export default class SecEdgarApi {
256
297
  filedDate: string;
257
298
  }[];
258
299
  }>;
300
+ getCurrentFilings(params?: GetCurrentFilingsParams): Promise<import("../../types").CurrentFilingsList>;
301
+ /**
302
+ * @see https://www.sec.gov/structureddata/rss-feeds-submitted-filings
303
+ */
304
+ getCurrentFilingsXBRL(params?: {
305
+ taxonomy?: 'usGaap' | 'mutualFund' | 'inlineXbrl' | 'allXbrl';
306
+ }): Promise<import("../../types").CurrentFilingsXBRL>;
307
+ /**
308
+ * Gets insider transactions for a provided symbol or CIK.
309
+ *
310
+ * To get transactions by a specific owner, set isOwnerCik to true and provide
311
+ * the owner CIK for the symbol parameter.
312
+ *
313
+ * example at https://www.sec.gov/cgi-bin/own-disp?action=getissuer&CIK=0000320193
314
+ */
315
+ getInsiderTransactions(params: GetInsiderTransactionsParams): Promise<{
316
+ transactions: import("../../types").InsiderTransaction[];
317
+ owners: import("../../types").Owner[];
318
+ issuers: import("../../types").Issuer[];
319
+ }>;
320
+ /**
321
+ * Search for companies from by name, sic code, or state.
322
+ */
323
+ searchCompanies(params: SearchCompaniesParams): Promise<{
324
+ items: import("../../types").CompanySearchResult[];
325
+ }>;
259
326
  }
260
327
  export {};