sec-edgar-api 0.2.2 → 0.2.3

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 (58) hide show
  1. package/README.md +5 -3
  2. package/build/services/DocumentParser/XMLParser.d.ts +5 -20
  3. package/build/services/DocumentParser/XMLParser.js +118 -122
  4. package/build/services/DocumentParser/parsers/index.d.ts +3 -5
  5. package/build/services/DocumentParser/parsers/index.js +3 -5
  6. package/build/services/DocumentParser/parsers/parse-form-13g.js +2 -2
  7. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +1 -6
  8. package/build/services/DocumentParser/parsers/parse-form-4.js +204 -134
  9. package/build/services/DocumentParser/parsers/parse-form-def14a.d.ts +2 -1
  10. package/build/services/DocumentParser/parsers/parse-form-def14a.js +106 -157
  11. package/build/services/ReportBuilder/FactFiscalCalculator.d.ts +4 -0
  12. package/build/services/ReportBuilder/FactFiscalCalculator.js +4 -0
  13. package/build/services/ReportBuilder/FactPeriodResolver.d.ts +6 -2
  14. package/build/services/ReportBuilder/FactPeriodResolver.js +6 -1
  15. package/build/services/ReportBuilder/FactRecordBuilder.d.ts +4 -1
  16. package/build/services/ReportBuilder/FactRecordBuilder.js +26 -4
  17. package/build/services/ReportBuilder/FactSplitAdjuster.d.ts +7 -0
  18. package/build/services/ReportBuilder/FactSplitAdjuster.js +19 -8
  19. package/build/services/ReportBuilder/ReportBuilder.d.ts +3 -0
  20. package/build/services/ReportBuilder/ReportBuilder.js +15 -9
  21. package/build/services/ReportParser/ReportParser.d.ts +3 -3
  22. package/build/services/ReportParser/ReportParser.js +7 -4
  23. package/build/services/ReportParser/ReportRawParser.d.ts +3 -9
  24. package/build/services/ReportParser/ReportRawParser.js +5 -33
  25. package/build/services/ReportParser/ReportWrapper.js +2 -0
  26. package/build/services/ReportParser/resolvers/resolve-fiscal-year-cumulative-properties.js +2 -1
  27. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +45 -84
  28. package/build/services/SecEdgarApi/SecEdgarApi.js +108 -246
  29. package/build/types/index.d.ts +2 -2
  30. package/build/types/index.js +2 -2
  31. package/build/types/parsed-filings.type.d.ts +5 -144
  32. package/build/types/report-raw.type.d.ts +3 -1
  33. package/build/types/report-translated.type.d.ts +4 -1
  34. package/build/types/submission.type.d.ts +2 -3
  35. package/build/util/key-translations.js +5 -1
  36. package/package.json +2 -5
  37. package/build/services/DocumentParser/HtmlTableExtractor.d.ts +0 -41
  38. package/build/services/DocumentParser/HtmlTableExtractor.js +0 -408
  39. package/build/services/DocumentParser/parsers/parse-current-filings.d.ts +0 -3
  40. package/build/services/DocumentParser/parsers/parse-current-filings.js +0 -98
  41. package/build/services/DocumentParser/parsers/parse-form-13f.d.ts +0 -6
  42. package/build/services/DocumentParser/parsers/parse-form-13f.js +0 -91
  43. package/build/services/ReportParser/FactItem.d.ts +0 -66
  44. package/build/services/ReportParser/FactItem.js +0 -50
  45. package/build/services/ReportParser/FactItemFactory.d.ts +0 -22
  46. package/build/services/ReportParser/FactItemFactory.js +0 -150
  47. package/build/services/ReportParser/FactIterator.d.ts +0 -18
  48. package/build/services/ReportParser/FactIterator.js +0 -35
  49. package/build/services/ReportParser/FactSplitMap.d.ts +0 -16
  50. package/build/services/ReportParser/FactSplitMap.js +0 -101
  51. package/build/types/current-filings-xml.type.d.ts +0 -74
  52. package/build/types/current-filings-xml.type.js +0 -6
  53. package/build/types/current-filings.type.d.ts +0 -44
  54. package/build/types/current-filings.type.js +0 -2
  55. package/build/types/form-13f-xml.type.d.ts +0 -105
  56. package/build/types/form-13f-xml.type.js +0 -2
  57. package/build/types/form-4-xml.type.d.ts +0 -132
  58. package/build/types/form-4-xml.type.js +0 -2
package/README.md CHANGED
@@ -24,10 +24,14 @@ Reports are all returned as a uniform interface:
24
24
 
25
25
  ```TS
26
26
  interface ReportTranslated {
27
- dateReport: string
27
+ cik: number
28
+ url: string | null
29
+ dateReport: string
28
30
  dateFiled: string
29
31
  fiscalPeriod: FiscalPeriod
30
32
  fiscalYear: number
33
+ splitDate: string | null
34
+ splitRatio: number | null
31
35
 
32
36
  assetTotal: number | null
33
37
  assetCurrent: number | null
@@ -92,8 +96,6 @@ interface ReportTranslated {
92
96
  cashFlowDeferredTax: number | null
93
97
 
94
98
  cashFlowWorkingCapitalNonCash: number | null
95
-
96
- splitRatio: number | null
97
99
  }
98
100
  ```
99
101
 
@@ -1,3 +1,4 @@
1
+ import { DocumentNode } from './XMLNode/DocumentNode';
1
2
  interface OnCharacterData {
2
3
  char: string;
3
4
  index: number;
@@ -5,7 +6,9 @@ interface OnCharacterData {
5
6
  pathOccurrenceCount: number;
6
7
  attributesStr: string;
7
8
  }
8
- type ObjOrArr = Record<string | symbol | number, any> | any[];
9
+ interface ParseTableNodesParams {
10
+ xml: string;
11
+ }
9
12
  interface Parse2Params {
10
13
  xml: string;
11
14
  onCharacter?: (data: OnCharacterData) => void;
@@ -26,30 +29,12 @@ interface IterateTablesParams {
26
29
  textMap: Map<string, string>;
27
30
  }) => void;
28
31
  }
29
- interface Parser {
30
- parse(xml: string): Record<string, any>;
31
- }
32
- interface XMLParserArgs {
33
- parser: Parser;
34
- }
35
- interface Section {
36
- text: string;
37
- tables: string[][][][];
38
- }
39
32
  export default class XMLParser {
40
- private readonly parser;
41
- constructor(args?: XMLParserArgs);
42
- extractJsonKey(json: Record<string, any>, extractKey: string): Record<string, any>;
43
- parse(xml: string): any;
44
- /**
45
- * Return true in the callback if you want the loop to stop
46
- */
47
- iterateKeysDeep(obj: ObjOrArr, cb: (key: string, currentObj: ObjOrArr, originalObj: ObjOrArr) => void | boolean): void;
48
- parseSectionTables(xml: string): Section[];
49
33
  iterateXML(params: Parse2Params): string[];
50
34
  /**
51
35
  * Returns text in each table cell mapped by `${table}.${row}.${col}`
52
36
  */
53
37
  getTableTextMap(params: IterateTablesParams): Map<string, string>;
38
+ getDocumentNode(params: ParseTableNodesParams): DocumentNode;
54
39
  }
55
40
  export {};
@@ -10,131 +10,16 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
- if (ar || !(i in from)) {
16
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
- ar[i] = from[i];
18
- }
19
- }
20
- return to.concat(ar || Array.prototype.slice.call(from));
21
- };
22
13
  Object.defineProperty(exports, "__esModule", { value: true });
23
- var fast_xml_parser_1 = require("fast-xml-parser");
14
+ var ColNode_1 = require("./XMLNode/ColNode");
15
+ var DocumentNode_1 = require("./XMLNode/DocumentNode");
16
+ var HRNode_1 = require("./XMLNode/HRNode");
17
+ var NonTableNode_1 = require("./XMLNode/NonTableNode");
18
+ var RowNode_1 = require("./XMLNode/RowNode");
19
+ var TableNode_1 = require("./XMLNode/TableNode");
24
20
  var XMLParser = /** @class */ (function () {
25
- function XMLParser(args) {
26
- var _a = (args !== null && args !== void 0 ? args : {}).parser, parser = _a === void 0 ? new fast_xml_parser_1.XMLParser() : _a;
27
- this.parser = parser;
21
+ function XMLParser() {
28
22
  }
29
- XMLParser.prototype.extractJsonKey = function (json, extractKey) {
30
- var obj = {};
31
- this.iterateKeysDeep(json, function (key, currentObj) {
32
- if (key === extractKey) {
33
- obj = currentObj[key];
34
- return true;
35
- }
36
- });
37
- return obj;
38
- };
39
- XMLParser.prototype.parse = function (xml) {
40
- return this.parser.parse(xml);
41
- };
42
- /**
43
- * Return true in the callback if you want the loop to stop
44
- */
45
- XMLParser.prototype.iterateKeysDeep = function (obj, cb) {
46
- var originalObj = obj;
47
- // prevents original object from being modified
48
- var _iterateKeys = function (obj, cb) {
49
- for (var key in obj) {
50
- var shouldBreak = cb(key, obj, originalObj) === true;
51
- if (shouldBreak)
52
- return;
53
- var value = obj[key];
54
- var isObjOrArr = typeof value === 'object' && value !== null;
55
- if (isObjOrArr)
56
- _iterateKeys(obj[key], cb);
57
- }
58
- };
59
- _iterateKeys(obj, cb);
60
- };
61
- XMLParser.prototype.parseSectionTables = function (xml) {
62
- var _this = this;
63
- var xmlSplit = xml.split(/<HR.*?>/gi);
64
- var fastParser = new fast_xml_parser_1.XMLParser({
65
- htmlEntities: true,
66
- ignoreAttributes: false,
67
- alwaysCreateTextNode: true,
68
- });
69
- var toArray = function (value) { return (Array.isArray(value) ? value : [value]); };
70
- var parseTable = function (obj) {
71
- var _a, _b, _c, _d;
72
- var getRowStrings = function (rows) {
73
- var _a, _b, _c;
74
- var results = [];
75
- for (var i = 0; i < rows.length; i++) {
76
- var obj_1 = rows[i];
77
- var isObject = typeof obj_1 === 'object' && obj_1;
78
- var cols = isObject ? (_c = (_b = (_a = obj_1['TD']) !== null && _a !== void 0 ? _a : obj_1['td']) !== null && _b !== void 0 ? _b : obj_1['TH']) !== null && _c !== void 0 ? _c : obj_1['th'] : [];
79
- var rowCols = [];
80
- var _loop_1 = function (a) {
81
- var col = cols[a];
82
- if (typeof col !== 'object' || !col) {
83
- rowCols.push(String(col || '').trim());
84
- }
85
- var colStr = '';
86
- _this.iterateKeysDeep(col, function (key, curObj) {
87
- var _a;
88
- if (!key.startsWith('@_')) {
89
- colStr = "".concat((_a = curObj[key]) !== null && _a !== void 0 ? _a : '').trim();
90
- }
91
- });
92
- rowCols.push(String(colStr || '').trim());
93
- var colSpan = !Array.isArray(col) ? Number(col['@_COLSPAN']) || 1 : 1;
94
- for (var c = 1; c < colSpan; c++) {
95
- rowCols.push('@_SPAN');
96
- }
97
- };
98
- for (var a = 0; a < (cols !== null && cols !== void 0 ? cols : []).length; a++) {
99
- _loop_1(a);
100
- }
101
- results.push(rowCols);
102
- }
103
- return results;
104
- };
105
- var table = toArray(obj);
106
- var thead = toArray((_b = (_a = table['THEAD']) !== null && _a !== void 0 ? _a : table['thead']) !== null && _b !== void 0 ? _b : []);
107
- var tbody = toArray((_d = (_c = table['TBODY']) !== null && _c !== void 0 ? _c : table['tbody']) !== null && _d !== void 0 ? _d : []);
108
- var tableRows = __spreadArray(__spreadArray(__spreadArray([], thead, true), table, true), tbody, true).map(function (obj) { var _a, _b; return toArray((_b = (_a = obj['TR']) !== null && _a !== void 0 ? _a : obj['tr']) !== null && _b !== void 0 ? _b : []); }).flat();
109
- var tableData = [];
110
- tableData.push(getRowStrings(tableRows));
111
- return tableData;
112
- };
113
- var sections = [];
114
- xmlSplit.forEach(function (xml) {
115
- var tableIndex = xml.indexOf('<TABLE');
116
- tableIndex = tableIndex === -1 ? xml.indexOf('<table') : tableIndex;
117
- var text = xml
118
- .substring(0, tableIndex)
119
- .replace(/<\/?(.|\n)*?>/gi, ' ')
120
- .replace(/\s+/g, ' ');
121
- var xmlTables = xml
122
- .replace(/<(?!(\/?TABLE|\/?TR|\/?TD|\/?TH|\/?HTML))(.|\n)*?>/gi, ' ')
123
- .replace(/\s+/g, ' ');
124
- var tableObjects = fastParser.parse(xmlTables);
125
- var tableObjectsFlat = [];
126
- _this.iterateKeysDeep(tableObjects, function (key, curObj) {
127
- if (key.toLowerCase() === 'table') {
128
- tableObjectsFlat.push.apply(tableObjectsFlat, toArray(curObj[key]));
129
- }
130
- });
131
- var tables = tableObjectsFlat.map(function (t) { return parseTable(t)[0]; });
132
- if (tables.length > 0) {
133
- sections.push({ text: text, tables: tables });
134
- }
135
- });
136
- return sections;
137
- };
138
23
  XMLParser.prototype.iterateXML = function (params) {
139
24
  var _a, _b, _c;
140
25
  var xml = params.xml, onCharacter = params.onCharacter, onCloseTag = params.onCloseTag, onOpenTag = params.onOpenTag;
@@ -306,6 +191,117 @@ var XMLParser = /** @class */ (function () {
306
191
  });
307
192
  return textByColKey;
308
193
  };
194
+ XMLParser.prototype.getDocumentNode = function (params) {
195
+ var xml = params.xml;
196
+ var rowsArr = [];
197
+ var colsArr = [];
198
+ var documentNode = new DocumentNode_1.DocumentNode();
199
+ var curNode = null;
200
+ var prevRowCols = [];
201
+ var curRowCols = [];
202
+ var isBold = false;
203
+ var boldPath = null;
204
+ var pushColToRow = function (col) {
205
+ var _a;
206
+ var colIndex = curRowCols.length;
207
+ col.setIndex(colIndex);
208
+ var colSpan = col.getColSpan();
209
+ Array.from({ length: colSpan }).forEach(function () { return curRowCols.push(col); });
210
+ var topSibling = (_a = prevRowCols[colIndex]) !== null && _a !== void 0 ? _a : null;
211
+ topSibling === null || topSibling === void 0 ? void 0 : topSibling.addBottomSibling(col);
212
+ };
213
+ this.iterateXML({
214
+ xml: xml,
215
+ onCloseTag: function (_a) {
216
+ var _b;
217
+ var path = _a.path;
218
+ var tag = path.split('.').pop();
219
+ if ((curNode === null || curNode === void 0 ? void 0 : curNode.getPath()) === boldPath) {
220
+ curNode === null || curNode === void 0 ? void 0 : curNode.setText("".concat((_b = curNode === null || curNode === void 0 ? void 0 : curNode.getText()) !== null && _b !== void 0 ? _b : '', "}}"));
221
+ boldPath = null;
222
+ }
223
+ },
224
+ onCharacter: function (_a) {
225
+ var _b;
226
+ var char = _a.char;
227
+ curNode === null || curNode === void 0 ? void 0 : curNode.setText(((_b = curNode === null || curNode === void 0 ? void 0 : curNode.getText()) !== null && _b !== void 0 ? _b : '') + char);
228
+ },
229
+ onOpenTag: function (_a) {
230
+ var _b;
231
+ var path = _a.path, attributesStr = _a.attributesStr;
232
+ // skip nested tables
233
+ if (path.split('.').reduce(function (acc, cur) { return (cur === 'table' ? acc + 1 : acc); }, 0) > 1)
234
+ return;
235
+ var tag = path.split('.').pop();
236
+ var isInTable = path.includes('table');
237
+ var topLevelNodes = documentNode.getChildren();
238
+ var prevTopLevelNode = topLevelNodes[topLevelNodes.length - 1];
239
+ var wasHorizontalLine = prevTopLevelNode instanceof HRNode_1.HRNode;
240
+ var wasNonTableNode = prevTopLevelNode instanceof NonTableNode_1.NonTableNode;
241
+ var wasBold = isBold;
242
+ var attributesLower = attributesStr.toLowerCase().replace(/\s/g, '');
243
+ isBold =
244
+ tag === 'b' ||
245
+ tag === 'strong' ||
246
+ attributesLower.includes('font-weight:bold') ||
247
+ attributesLower.includes('font-weight:700') ||
248
+ attributesLower.includes('font-weight:800') ||
249
+ attributesLower.includes('font-weight:900');
250
+ if (!isInTable) {
251
+ prevRowCols = [];
252
+ curRowCols = [];
253
+ }
254
+ if (tag === 'hr' && !isInTable) {
255
+ var hr = new HRNode_1.HRNode({ attributesStr: attributesStr, path: path });
256
+ hr.setPreviousSibling(prevTopLevelNode !== null && prevTopLevelNode !== void 0 ? prevTopLevelNode : null);
257
+ topLevelNodes.push(hr);
258
+ curNode = hr;
259
+ }
260
+ else if (tag === 'table') {
261
+ var table = new TableNode_1.TableNode({ attributesStr: attributesStr, path: path });
262
+ table.setPreviousSibling(prevTopLevelNode !== null && prevTopLevelNode !== void 0 ? prevTopLevelNode : null);
263
+ topLevelNodes.push(table);
264
+ curNode = table;
265
+ }
266
+ else if (tag === 'tr') {
267
+ var row = new RowNode_1.RowNode({ attributesStr: attributesStr, path: path });
268
+ var prevRow = rowsArr[rowsArr.length - 1];
269
+ row.setParent(prevTopLevelNode);
270
+ row.setPreviousSibling((prevRow === null || prevRow === void 0 ? void 0 : prevRow.getParent()) === row.getParent() ? prevRow : null);
271
+ rowsArr.push(row);
272
+ prevRowCols = curRowCols;
273
+ curRowCols = [];
274
+ curNode = row;
275
+ }
276
+ else if (tag === 'td' || tag === 'th') {
277
+ var col = new ColNode_1.ColNode({ attributesStr: attributesStr, path: path });
278
+ var prevCol = colsArr[colsArr.length - 1];
279
+ col.setParent(rowsArr[rowsArr.length - 1]);
280
+ col.setPreviousSibling((prevCol === null || prevCol === void 0 ? void 0 : prevCol.getParent()) === col.getParent() ? prevCol : null);
281
+ colsArr.push(col);
282
+ pushColToRow(col);
283
+ curNode = col;
284
+ }
285
+ else if ((!isInTable && !wasNonTableNode) || (wasHorizontalLine && tag !== 'hr')) {
286
+ var node = new NonTableNode_1.NonTableNode({ attributesStr: attributesStr, path: path });
287
+ node.setPreviousSibling(prevTopLevelNode !== null && prevTopLevelNode !== void 0 ? prevTopLevelNode : null);
288
+ topLevelNodes.push(node);
289
+ curNode = node;
290
+ }
291
+ else if (curNode && !curNode.getText().endsWith('\n')) {
292
+ curNode.setText("".concat(curNode.getText().trim(), "\n"));
293
+ }
294
+ if (isBold && !wasBold && !(curNode === null || curNode === void 0 ? void 0 : curNode.getText().endsWith('{{'))) {
295
+ curNode === null || curNode === void 0 ? void 0 : curNode.setText("".concat(curNode === null || curNode === void 0 ? void 0 : curNode.getText().trim(), "{{"));
296
+ }
297
+ if (isBold) {
298
+ boldPath = (_b = curNode === null || curNode === void 0 ? void 0 : curNode.getPath()) !== null && _b !== void 0 ? _b : null;
299
+ }
300
+ },
301
+ });
302
+ documentNode.setText(xml);
303
+ return documentNode;
304
+ };
309
305
  return XMLParser;
310
306
  }());
311
307
  exports.default = XMLParser;
@@ -1,13 +1,11 @@
1
- import { parseCurrentFilings } from './parse-current-filings';
2
- import { parseForm13f } from './parse-form-13f';
3
- import { parseForm13g } from './parse-form-13g';
4
1
  import { parseForm4 } from './parse-form-4';
2
+ import { parseForm13g } from './parse-form-13g';
3
+ import { parseForm10k } from './parse-form-10k';
5
4
  import { parseFormDef14a } from './parse-form-def14a';
6
5
  declare const parsers: {
7
6
  parseForm4: typeof parseForm4;
8
7
  parseForm13g: typeof parseForm13g;
9
- parseForm13f: typeof parseForm13f;
8
+ parseForm10k: typeof parseForm10k;
10
9
  parseFormDef14a: typeof parseFormDef14a;
11
- parseCurrentFilings: typeof parseCurrentFilings;
12
10
  };
13
11
  export default parsers;
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var parse_current_filings_1 = require("./parse-current-filings");
4
- var parse_form_13f_1 = require("./parse-form-13f");
5
- var parse_form_13g_1 = require("./parse-form-13g");
6
3
  var parse_form_4_1 = require("./parse-form-4");
4
+ var parse_form_13g_1 = require("./parse-form-13g");
5
+ var parse_form_10k_1 = require("./parse-form-10k");
7
6
  var parse_form_def14a_1 = require("./parse-form-def14a");
8
7
  var parsers = {
9
8
  parseForm4: parse_form_4_1.parseForm4,
10
9
  parseForm13g: parse_form_13g_1.parseForm13g,
11
- parseForm13f: parse_form_13f_1.parseForm13f,
10
+ parseForm10k: parse_form_10k_1.parseForm10k,
12
11
  parseFormDef14a: parse_form_def14a_1.parseFormDef14a,
13
- parseCurrentFilings: parse_current_filings_1.parseCurrentFilings,
14
12
  };
15
13
  exports.default = parsers;
@@ -58,7 +58,7 @@ function parseForm13g(params, xmlParser) {
58
58
  return "continue";
59
59
  var textParts = text.split('&nbsp;').filter(function (t) { return t.trim() !== ''; });
60
60
  var colNameIndex = textParts.findIndex(function (t) { return getKey(t) === colName; });
61
- var value = ((_c = (_b = textParts[colNameIndex + 1]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '').replace(/&.*?;/g, ' ').replace(/\s+/g, ' ').trim();
61
+ var value = (_c = (_b = textParts[colNameIndex + 1]) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
62
62
  switch (colName) {
63
63
  case 'shares':
64
64
  holder.shares = Number(value.replace(/[^0-9]/g, '')) || 0;
@@ -83,6 +83,6 @@ function parseForm13g(params, xmlParser) {
83
83
  if (((_d = holders[holders.length - 1]) === null || _d === void 0 ? void 0 : _d.name) === '') {
84
84
  holders.pop();
85
85
  }
86
- return { institutionalHolders: holders };
86
+ return { holders: holders };
87
87
  }
88
88
  exports.parseForm13g = parseForm13g;
@@ -1,12 +1,7 @@
1
1
  import { Form4Data, XMLParams } from '../../../types';
2
2
  import XMLParser from '../XMLParser';
3
3
  /**
4
- * Form 4 and form 5 - Insider Transactions
5
- *
6
- * TODO: sometimes not working. keys not consistently coming back objects vs arrays:
7
- *
8
- * here reporting owner is array, so not being extracted correctly
9
- * https://www.sec.gov/Archives/edgar/data/1067983/000095017024044198/0000950170-24-044198.txt
4
+ * Form 4 - Insider Transactions
10
5
  *
11
6
  * example at https://www.sec.gov/Archives/edgar/data/320193/000032019323000079/xslF345X05/wk-form4_1691533817.xml
12
7
  */