sec-edgar-api 0.0.6 → 0.0.7

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 (65) hide show
  1. package/build/index.js +5 -1
  2. package/build/services/Client/Client.d.ts +2 -1
  3. package/build/services/Client/index.js +5 -1
  4. package/build/services/DocumentParser/DocumentParser.d.ts +1 -0
  5. package/build/services/DocumentParser/DocumentParser.js +3 -0
  6. package/build/services/DocumentParser/XMLNode/ColNode.d.ts +18 -0
  7. package/build/services/DocumentParser/XMLNode/ColNode.js +74 -0
  8. package/build/services/DocumentParser/XMLNode/DocumentNode.d.ts +3 -0
  9. package/build/services/DocumentParser/XMLNode/DocumentNode.js +27 -0
  10. package/build/services/DocumentParser/XMLNode/HRNode.d.ts +3 -0
  11. package/build/services/DocumentParser/XMLNode/HRNode.js +27 -0
  12. package/build/services/DocumentParser/XMLNode/NonTableNode.d.ts +3 -0
  13. package/build/services/DocumentParser/XMLNode/NonTableNode.js +27 -0
  14. package/build/services/DocumentParser/XMLNode/RowNode.d.ts +30 -0
  15. package/build/services/DocumentParser/XMLNode/RowNode.js +177 -0
  16. package/build/services/DocumentParser/XMLNode/TableNode.d.ts +20 -0
  17. package/build/services/DocumentParser/XMLNode/TableNode.js +132 -0
  18. package/build/services/DocumentParser/XMLNode/XMLNode.d.ts +37 -0
  19. package/build/services/DocumentParser/XMLNode/XMLNode.js +154 -0
  20. package/build/services/DocumentParser/XMLParser.d.ts +15 -0
  21. package/build/services/DocumentParser/XMLParser.js +180 -52
  22. package/build/services/DocumentParser/parsers/index.d.ts +2 -0
  23. package/build/services/DocumentParser/parsers/index.js +2 -0
  24. package/build/services/DocumentParser/parsers/parse-form-10k.d.ts +3 -0
  25. package/build/services/DocumentParser/parsers/parse-form-10k.js +78 -0
  26. package/build/services/ReportParser/ReportParser.d.ts +3 -3
  27. package/build/services/ReportParser/ReportParser.js +8 -4
  28. package/build/services/ReportParser/ReportTranslatedProxy.d.ts +1 -1
  29. package/build/services/ReportParser/ReportWrapper.js +2 -1
  30. package/build/services/ReportParser/resolvers/helpers.d.ts +1 -1
  31. package/build/services/SecEdgarApi/RequestWrapper.d.ts +19 -12
  32. package/build/services/SecEdgarApi/RequestWrapper.js +52 -38
  33. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +22 -9
  34. package/build/services/SecEdgarApi/SecEdgarApi.js +48 -25
  35. package/build/services/SecEdgarApi/Throttler.js +1 -1
  36. package/build/services/SecEdgarApi/index.js +5 -1
  37. package/build/types/index.js +5 -1
  38. package/build/types/parsed-filings.type.d.ts +11 -3
  39. package/build/types/report-raw.type.d.ts +3 -3
  40. package/package.json +1 -1
  41. package/build/.DS_Store +0 -0
  42. package/build/downloader.d.ts +0 -6
  43. package/build/downloader.js +0 -9
  44. package/build/services/FactFileReader/FactFileReader.d.ts +0 -30
  45. package/build/services/FactFileReader/FactFileReader.js +0 -36
  46. package/build/services/FactFileReader/index.d.ts +0 -2
  47. package/build/services/FactFileReader/index.js +0 -4
  48. package/build/services/FactsDownloader/Downloader.d.ts +0 -26
  49. package/build/services/FactsDownloader/Downloader.js +0 -102
  50. package/build/services/FactsDownloader/FactsDownloader.d.ts +0 -37
  51. package/build/services/FactsDownloader/FactsDownloader.js +0 -131
  52. package/build/services/FactsDownloader/Unzipper.d.ts +0 -40
  53. package/build/services/FactsDownloader/Unzipper.js +0 -40
  54. package/build/services/FactsDownloader/index.d.ts +0 -2
  55. package/build/services/FactsDownloader/index.js +0 -4
  56. package/build/services/SecEdgarApi/Client.d.ts +0 -44
  57. package/build/services/SecEdgarApi/Client.js +0 -104
  58. package/build/services/SecEdgarApi/Downloader.d.ts +0 -26
  59. package/build/services/SecEdgarApi/Downloader.js +0 -102
  60. package/build/services/SecEdgarApi/FactsDownloader.d.ts +0 -30
  61. package/build/services/SecEdgarApi/FactsDownloader.js +0 -124
  62. package/build/services/SecEdgarApi/SecConnector.d.ts +0 -47
  63. package/build/services/SecEdgarApi/SecConnector.js +0 -143
  64. package/build/services/SecEdgarApi/Unzipper.d.ts +0 -40
  65. package/build/services/SecEdgarApi/Unzipper.js +0 -40
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XMLNode = void 0;
4
+ var XMLNode = /** @class */ (function () {
5
+ function XMLNode(args) {
6
+ this.parent = null;
7
+ this.previousSibling = null;
8
+ this.nextSibling = null;
9
+ this.children = [];
10
+ this.text = '';
11
+ this.attributesStr = '';
12
+ this.path = '';
13
+ var _a = args !== null && args !== void 0 ? args : {}, _b = _a.attributesStr, attributesStr = _b === void 0 ? '' : _b, _c = _a.path, path = _c === void 0 ? '' : _c;
14
+ var pathParts = path.split('.').filter(function (str) { return !str.includes(':'); });
15
+ this.attributesStr = attributesStr;
16
+ this.path = pathParts.join('.');
17
+ }
18
+ XMLNode.prototype.getSiblings = function (params) {
19
+ var _a = params.stopAtType, stopAtType = _a === void 0 ? XMLNode : _a, dir = params.dir, _b = params.includeStopAtType, includeStopAtType = _b === void 0 ? false : _b;
20
+ var isPrevious = dir === 'previous';
21
+ var siblings = [];
22
+ var nextSibling = isPrevious ? this.getPreviousSibling() : this.getNextSibling();
23
+ var i = 0;
24
+ while (nextSibling && !(nextSibling instanceof stopAtType)) {
25
+ siblings.push(nextSibling);
26
+ nextSibling = isPrevious
27
+ ? nextSibling.getPreviousSibling()
28
+ : nextSibling.getNextSibling();
29
+ i++;
30
+ if (i > 1000)
31
+ throw new Error('infinite loop');
32
+ }
33
+ if (includeStopAtType && nextSibling instanceof stopAtType) {
34
+ siblings.push(nextSibling);
35
+ }
36
+ return siblings;
37
+ };
38
+ XMLNode.prototype.extractBold = function (str) {
39
+ var _a, _b;
40
+ if (str === void 0) { str = this.text; }
41
+ var boldText = (_b = (_a = str
42
+ .replace(/\n/g, '')
43
+ .replace(/\}\}\{\{/g, ' | ')
44
+ .replace(/ | /g, ' ')
45
+ .replace(/–/g, '- ')
46
+ .match(/(?<=\{\{).*?(?=\}\})/g)) === null || _a === void 0 ? void 0 : _a.join(' || ')) !== null && _b !== void 0 ? _b : '';
47
+ return boldText.replace(/\s+/g, ' ').trim();
48
+ };
49
+ XMLNode.prototype.parseValue = function (str) {
50
+ if (str === void 0) { str = this.text; }
51
+ if (str === null)
52
+ return null;
53
+ var text = str
54
+ .replace(/\n|&#160;|&nbsp;/g, ' ')
55
+ .replace(/&#174;/g, '')
56
+ .replace(/&#8211;|&#8212;|&#x2014;/g, '-')
57
+ .replace(/&#8217;|&#8220;|&#8221;/g, "'")
58
+ .replace(/\}\}\{\{/g, ' ')
59
+ .replace(/\{\{|\}\}/g, '')
60
+ .replace(/\s+/, ' ')
61
+ .trim();
62
+ if (str.replace(/&#8211;|&#8212;|&#x2014;/g, '-') === '-')
63
+ return '-';
64
+ if (text === '')
65
+ return null;
66
+ var colNum = text.replace(/,|\(|\)|\%/g, '').trim();
67
+ if (colNum === '-' || colNum === '$')
68
+ return null;
69
+ colNum = colNum.replace(/\-|\$/g, '');
70
+ if (!isNaN(Number(colNum))) {
71
+ if (text.includes('%'))
72
+ return text.replace(/[^a-zA-Z\d\s:]/g, '') === '' ? null : text;
73
+ return text.includes('(') || text.includes('-') ? Number(colNum) * -1 : Number(colNum);
74
+ }
75
+ return text;
76
+ };
77
+ XMLNode.prototype.setPreviousSibling = function (node) {
78
+ var prevPreviousSibling = this.previousSibling;
79
+ this.previousSibling = node;
80
+ if ((prevPreviousSibling === null || prevPreviousSibling === void 0 ? void 0 : prevPreviousSibling.getNextSibling()) === this) {
81
+ prevPreviousSibling.setNextSibling(null);
82
+ }
83
+ if ((node === null || node === void 0 ? void 0 : node.getNextSibling()) !== this) {
84
+ node === null || node === void 0 ? void 0 : node.setNextSibling(this);
85
+ }
86
+ };
87
+ XMLNode.prototype.setNextSibling = function (node) {
88
+ var prevNextSibling = this.nextSibling;
89
+ this.nextSibling = node;
90
+ if ((prevNextSibling === null || prevNextSibling === void 0 ? void 0 : prevNextSibling.getPreviousSibling()) === this) {
91
+ prevNextSibling.setPreviousSibling(null);
92
+ }
93
+ if ((node === null || node === void 0 ? void 0 : node.getPreviousSibling()) !== this) {
94
+ node === null || node === void 0 ? void 0 : node.setPreviousSibling(this);
95
+ }
96
+ };
97
+ XMLNode.prototype.removeChild = function (node) {
98
+ this.children.splice(this.children.indexOf(node), 1);
99
+ if (node.getParent() === this) {
100
+ node.setParent(null);
101
+ }
102
+ };
103
+ XMLNode.prototype.setParent = function (node) {
104
+ var prevParent = this.parent;
105
+ this.parent = node;
106
+ if (prevParent === null || prevParent === void 0 ? void 0 : prevParent.getChildren().includes(this)) {
107
+ prevParent.removeChild(this);
108
+ }
109
+ if (!(node === null || node === void 0 ? void 0 : node.getChildren().includes(this))) {
110
+ node === null || node === void 0 ? void 0 : node.addChild(this);
111
+ }
112
+ };
113
+ XMLNode.prototype.getNextSibling = function () {
114
+ return this.nextSibling;
115
+ };
116
+ XMLNode.prototype.getPreviousSibling = function () {
117
+ return this.previousSibling;
118
+ };
119
+ XMLNode.prototype.getParent = function () {
120
+ return this.parent;
121
+ };
122
+ XMLNode.prototype.getAttributes = function () {
123
+ var _a;
124
+ var attributesObj = {};
125
+ (_a = this.attributesStr.match(/(\w+)=("[^"]*")/g)) === null || _a === void 0 ? void 0 : _a.forEach(function (attributeStr) {
126
+ var _a = attributeStr.split('='), key = _a[0], value = _a[1];
127
+ attributesObj[key.toLowerCase()] = value.replace(/"/g, '');
128
+ });
129
+ return attributesObj;
130
+ };
131
+ XMLNode.prototype.getAttributesStr = function () {
132
+ return this.attributesStr;
133
+ };
134
+ XMLNode.prototype.getChildren = function () {
135
+ return this.children;
136
+ };
137
+ XMLNode.prototype.addChild = function (node) {
138
+ this.children.push(node);
139
+ if (node.getParent() !== this) {
140
+ node.setParent(this);
141
+ }
142
+ };
143
+ XMLNode.prototype.getText = function () {
144
+ return this.text;
145
+ };
146
+ XMLNode.prototype.setText = function (text) {
147
+ this.text = text;
148
+ };
149
+ XMLNode.prototype.getPath = function () {
150
+ return this.path;
151
+ };
152
+ return XMLNode;
153
+ }());
154
+ exports.XMLNode = XMLNode;
@@ -1,8 +1,13 @@
1
+ import { DocumentNode } from './XMLNode/DocumentNode';
1
2
  interface OnCharacterData {
2
3
  char: string;
3
4
  index: number;
4
5
  path: string;
5
6
  pathOccurrenceCount: number;
7
+ attributesStr: string;
8
+ }
9
+ interface ParseTableNodesParams {
10
+ xml: string;
6
11
  }
7
12
  interface Parse2Params {
8
13
  xml: string;
@@ -14,6 +19,15 @@ interface IterateTablesParams {
14
19
  xml: string;
15
20
  parentPath?: string;
16
21
  trimSpaces?: boolean;
22
+ onCharacter?: (data: OnCharacterData & {
23
+ textMap: Map<string, string>;
24
+ }) => void;
25
+ onOpenTag?: (data: OnCharacterData & {
26
+ textMap: Map<string, string>;
27
+ }) => void;
28
+ onCloseTag?: (data: OnCharacterData & {
29
+ textMap: Map<string, string>;
30
+ }) => void;
17
31
  }
18
32
  export default class XMLParser {
19
33
  iterateXML(params: Parse2Params): string[];
@@ -21,5 +35,6 @@ export default class XMLParser {
21
35
  * Returns text in each table cell mapped by `${table}.${row}.${col}`
22
36
  */
23
37
  getTableTextMap(params: IterateTablesParams): Map<string, string>;
38
+ getDocumentNode(params: ParseTableNodesParams): DocumentNode;
24
39
  }
25
40
  export {};
@@ -1,10 +1,27 @@
1
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
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
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");
3
20
  var XMLParser = /** @class */ (function () {
4
21
  function XMLParser() {
5
22
  }
6
23
  XMLParser.prototype.iterateXML = function (params) {
7
- var _a, _b, _c, _d;
24
+ var _a, _b, _c;
8
25
  var xml = params.xml, onCharacter = params.onCharacter, onCloseTag = params.onCloseTag, onOpenTag = params.onOpenTag;
9
26
  var selfEnclosingTags = new Set([
10
27
  'filename',
@@ -26,70 +43,69 @@ var XMLParser = /** @class */ (function () {
26
43
  'track',
27
44
  'wbr',
28
45
  ]);
46
+ var spaceChars = new Set(['\n', '\r', '\t', ' ']);
29
47
  var pathOccurrenceCountMap = new Map();
30
48
  var curPath = '';
31
49
  var curTag = '';
50
+ var curAttributes = '';
32
51
  var didStart = false;
33
52
  var pathsArr = [];
34
53
  for (var i = 0; i < xml.length; i++) {
35
54
  var char = xml[i];
36
- if (char === '<' && xml[i + 1] !== '/' && xml[i + 1] !== '?' && xml[i + 1] !== '!') {
37
- var iOpen = i;
55
+ var isOpenTag = char === '<' && xml[i + 1] !== '/' && xml[i + 1] !== '?' && xml[i + 1] !== '!';
56
+ var isCloseTag = char === '<' && xml[i + 1] === '/';
57
+ var onCharacterData = {
58
+ char: char,
59
+ index: i,
60
+ path: curPath,
61
+ pathOccurrenceCount: (_a = pathOccurrenceCountMap.get(curPath)) !== null && _a !== void 0 ? _a : 0,
62
+ attributesStr: curAttributes,
63
+ };
64
+ if (isOpenTag) {
65
+ var didEndTagName = false;
66
+ var j = 0;
38
67
  didStart = true;
39
68
  i++;
40
- var j = 0;
41
- var didEndTagName = false;
42
69
  while (xml[i] !== '>') {
43
- didEndTagName =
44
- didEndTagName ||
45
- xml[i] === ' ' ||
46
- xml[i] === '\n' ||
47
- xml[i] === '\r' ||
48
- xml[i] === '\t' ||
49
- xml[i] === '/';
70
+ didEndTagName = didEndTagName || spaceChars.has(xml[i]) || xml[i] === '/';
50
71
  if (!didEndTagName) {
51
72
  curTag += xml[i].toLowerCase();
52
73
  }
74
+ else if (xml[i] !== '/') {
75
+ curAttributes += xml[i];
76
+ }
53
77
  i++;
54
78
  j++;
55
- if (j > 1000) {
79
+ if (j > 1000000) {
56
80
  throw new Error('too many iterations');
57
81
  }
58
82
  }
59
- // map path for non-self-enclosing tags
60
- if (!selfEnclosingTags.has(curTag)) {
61
- curPath = "".concat(curPath).concat(curPath.length > 0 ? '.' : '').concat(curTag).toLowerCase();
62
- var pathOccurrenceCount = (_a = pathOccurrenceCountMap.get(curPath)) !== null && _a !== void 0 ? _a : 0;
63
- pathOccurrenceCountMap.set(curPath, pathOccurrenceCount + 1);
64
- pathsArr.push(curPath);
65
- onOpenTag === null || onOpenTag === void 0 ? void 0 : onOpenTag({
66
- char: char,
67
- index: iOpen,
68
- path: curPath,
69
- pathOccurrenceCount: (_b = pathOccurrenceCountMap.get(curPath)) !== null && _b !== void 0 ? _b : 0,
70
- });
83
+ var pathNew = "".concat(curPath).concat(curPath.length > 0 ? '.' : '').concat(curTag).toLowerCase();
84
+ var countBefore = (_b = pathOccurrenceCountMap.get(pathNew)) !== null && _b !== void 0 ? _b : 0;
85
+ var pathOccurrenceCount = (_c = pathOccurrenceCountMap.set(pathNew, countBefore + 1).get(pathNew)) !== null && _c !== void 0 ? _c : 0;
86
+ onCharacterData.path = pathNew;
87
+ onCharacterData.pathOccurrenceCount = pathOccurrenceCount;
88
+ onCharacterData.attributesStr = curAttributes;
89
+ pathsArr.push(pathNew);
90
+ onOpenTag === null || onOpenTag === void 0 ? void 0 : onOpenTag(onCharacterData);
91
+ if (selfEnclosingTags.has(curTag)) {
92
+ onCloseTag === null || onCloseTag === void 0 ? void 0 : onCloseTag(onCharacterData);
93
+ }
94
+ else {
95
+ curPath = pathNew;
71
96
  }
72
97
  curTag = '';
73
98
  }
74
- else if (char === '<' && xml[i + 1] === '/') {
99
+ else if (isCloseTag) {
75
100
  while (xml[i] !== '>') {
76
101
  i++;
77
102
  }
78
- onCloseTag === null || onCloseTag === void 0 ? void 0 : onCloseTag({
79
- char: char,
80
- index: i,
81
- path: curPath,
82
- pathOccurrenceCount: (_c = pathOccurrenceCountMap.get(curPath)) !== null && _c !== void 0 ? _c : 0,
83
- });
103
+ onCloseTag === null || onCloseTag === void 0 ? void 0 : onCloseTag(onCharacterData);
84
104
  curPath = curPath.slice(0, curPath.lastIndexOf('.'));
105
+ curAttributes = '';
85
106
  }
86
107
  else if (didStart) {
87
- onCharacter === null || onCharacter === void 0 ? void 0 : onCharacter({
88
- char: char,
89
- index: i,
90
- path: curPath,
91
- pathOccurrenceCount: (_d = pathOccurrenceCountMap.get(curPath)) !== null && _d !== void 0 ? _d : 0,
92
- });
108
+ onCharacter === null || onCharacter === void 0 ? void 0 : onCharacter(onCharacterData);
93
109
  }
94
110
  }
95
111
  return pathsArr;
@@ -98,7 +114,7 @@ var XMLParser = /** @class */ (function () {
98
114
  * Returns text in each table cell mapped by `${table}.${row}.${col}`
99
115
  */
100
116
  XMLParser.prototype.getTableTextMap = function (params) {
101
- var xml = params.xml, parentPath = params.parentPath, _a = params.trimSpaces, trimSpaces = _a === void 0 ? true : _a;
117
+ var xml = params.xml, parentPath = params.parentPath, onCharacter = params.onCharacter, onCloseTag = params.onCloseTag, onOpenTag = params.onOpenTag, _a = params.trimSpaces, trimSpaces = _a === void 0 ? true : _a;
102
118
  var rowPaths = new Set([
103
119
  "".concat(parentPath, ".table.tbody.tr"),
104
120
  "".concat(parentPath, ".table.thead.tr"),
@@ -122,11 +138,11 @@ var XMLParser = /** @class */ (function () {
122
138
  var spaceChars = new Set(['\n', '\r', '\t']);
123
139
  this.iterateXML({
124
140
  xml: xml,
125
- onOpenTag: function (_a) {
126
- var _b;
127
- var path = _a.path;
141
+ onOpenTag: function (data) {
142
+ var _a;
143
+ var path = data.path;
128
144
  var colKey = "".concat(table, ".").concat(row, ".").concat(col);
129
- var textCur = (_b = textByColKey.get(colKey)) !== null && _b !== void 0 ? _b : '';
145
+ var textCur = (_a = textByColKey.get(colKey)) !== null && _a !== void 0 ? _a : '';
130
146
  var pathLower = path.toLowerCase();
131
147
  if (textCur.trim().length === 0 && col === 0) {
132
148
  textByColKey.delete(colKey);
@@ -148,18 +164,19 @@ var XMLParser = /** @class */ (function () {
148
164
  else if (isCol) {
149
165
  col++;
150
166
  }
167
+ onOpenTag === null || onOpenTag === void 0 ? void 0 : onOpenTag(__assign(__assign({}, data), { textMap: textByColKey }));
151
168
  },
152
- onCharacter: function (_a) {
153
- var _b;
154
- var char = _a.char;
155
- char = spaceChars.has(char) ? ' ' : char;
169
+ onCharacter: function (data) {
170
+ var _a;
171
+ var char = spaceChars.has(data.char) ? ' ' : data.char;
156
172
  var colKey = "".concat(table, ".").concat(row, ".").concat(col);
157
- var textCur = (_b = textByColKey.get(colKey)) !== null && _b !== void 0 ? _b : '';
158
- if (trimSpaces && char === ' ' && textCur.endsWith(' '))
159
- return;
160
- textByColKey.set(colKey, "".concat(textCur).concat(char));
173
+ var textCur = (_a = textByColKey.get(colKey)) !== null && _a !== void 0 ? _a : '';
174
+ if (!(trimSpaces && char === ' ' && textCur.endsWith(' '))) {
175
+ textByColKey.set(colKey, "".concat(textCur).concat(char));
176
+ }
177
+ onCharacter === null || onCharacter === void 0 ? void 0 : onCharacter(__assign(__assign({}, data), { textMap: textByColKey }));
161
178
  },
162
- onCloseTag: function () {
179
+ onCloseTag: function (data) {
163
180
  var _a;
164
181
  var colKey = "".concat(table, ".").concat(row, ".").concat(col);
165
182
  var textCur = (_a = textByColKey.get(colKey)) !== null && _a !== void 0 ? _a : '';
@@ -169,10 +186,121 @@ var XMLParser = /** @class */ (function () {
169
186
  else if (!textCur.endsWith(' ')) {
170
187
  textByColKey.set(colKey, "".concat(textCur, " "));
171
188
  }
189
+ onCloseTag === null || onCloseTag === void 0 ? void 0 : onCloseTag(__assign(__assign({}, data), { textMap: textByColKey }));
172
190
  },
173
191
  });
174
192
  return textByColKey;
175
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 colSpan = col.getColSpan();
207
+ var colIndex = curRowCols.length;
208
+ col.setIndex(colIndex);
209
+ for (var i = 0; i < colSpan; i++) {
210
+ curRowCols.push(col);
211
+ }
212
+ var topSibling = (_a = prevRowCols[colIndex]) !== null && _a !== void 0 ? _a : null;
213
+ topSibling === null || topSibling === void 0 ? void 0 : topSibling.addBottomSibling(col);
214
+ };
215
+ this.iterateXML({
216
+ xml: xml,
217
+ onCloseTag: function () {
218
+ var _a;
219
+ if ((curNode === null || curNode === void 0 ? void 0 : curNode.getPath()) === boldPath) {
220
+ curNode === null || curNode === void 0 ? void 0 : curNode.setText("".concat((_a = curNode === null || curNode === void 0 ? void 0 : curNode.getText()) !== null && _a !== void 0 ? _a : '', "}}"));
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
+ return documentNode;
303
+ };
176
304
  return XMLParser;
177
305
  }());
178
306
  exports.default = XMLParser;
@@ -1,7 +1,9 @@
1
1
  import { parseForm4 } from './parse-form-4';
2
2
  import { parseForm13g } from './parse-form-13g';
3
+ import { parseForm10k } from './parse-form-10k';
3
4
  declare const parsers: {
4
5
  parseForm4: typeof parseForm4;
5
6
  parseForm13g: typeof parseForm13g;
7
+ parseForm10k: typeof parseForm10k;
6
8
  };
7
9
  export default parsers;
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var parse_form_4_1 = require("./parse-form-4");
4
4
  var parse_form_13g_1 = require("./parse-form-13g");
5
+ var parse_form_10k_1 = require("./parse-form-10k");
5
6
  var parsers = {
6
7
  parseForm4: parse_form_4_1.parseForm4,
7
8
  parseForm13g: parse_form_13g_1.parseForm13g,
9
+ parseForm10k: parse_form_10k_1.parseForm10k,
8
10
  };
9
11
  exports.default = parsers;
@@ -0,0 +1,3 @@
1
+ import { TableData, XMLParams } from '../../../types';
2
+ import XMLParser from '../XMLParser';
3
+ export declare function parseForm10k(params: XMLParams, xmlParser?: XMLParser): TableData[];
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.parseForm10k = void 0;
13
+ var HRNode_1 = require("../XMLNode/HRNode");
14
+ var NonTableNode_1 = require("../XMLNode/NonTableNode");
15
+ var TableNode_1 = require("../XMLNode/TableNode");
16
+ var XMLParser_1 = require("../XMLParser");
17
+ function parseForm10k(params, xmlParser) {
18
+ var _a, _b, _c, _d;
19
+ if (xmlParser === void 0) { xmlParser = new XMLParser_1.default(); }
20
+ var xml = params.xml;
21
+ var doc = xmlParser.getDocumentNode({ xml: xml });
22
+ var nodes = doc.getChildren();
23
+ var tables = nodes.filter(function (child) { return child instanceof TableNode_1.TableNode; });
24
+ var curSectionIndex = 0;
25
+ var sectionIndexByTable = new Map();
26
+ var tableDataArr = [];
27
+ // map the section index of each table. new section starts for each <hr> tag.
28
+ for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
29
+ var node = nodes_1[_i];
30
+ if (node instanceof TableNode_1.TableNode) {
31
+ sectionIndexByTable.set(node, curSectionIndex);
32
+ }
33
+ else if (node instanceof HRNode_1.HRNode) {
34
+ curSectionIndex++;
35
+ }
36
+ }
37
+ var _loop_1 = function (table) {
38
+ table.mergeHeader();
39
+ table.removeEmptyTopRows();
40
+ var siblingsPrev = table.getSiblings({ dir: 'previous', stopAtType: NonTableNode_1.NonTableNode, includeStopAtType: true });
41
+ var siblingsNext = table.getSiblings({ dir: 'next', stopAtType: NonTableNode_1.NonTableNode, includeStopAtType: true });
42
+ // set the title based on the bold text in the previous siblings
43
+ var title = siblingsPrev.map(function (s) { return s.extractBold(); }).join(' | ');
44
+ var textBefore = siblingsPrev.map(function (s) { return s.getText(); }).join('\n');
45
+ var textAfter = siblingsNext.map(function (s) { return s.getText(); }).join('\n');
46
+ var header = table.getHeaderRow();
47
+ var headerTable = header === null || header === void 0 ? void 0 : header.toTable();
48
+ var topRow = table.getChildren()[0];
49
+ var topRowTable = !header ? topRow === null || topRow === void 0 ? void 0 : topRow.toTable() : null;
50
+ var prevTable = tableDataArr[tableDataArr.length - 1];
51
+ var isSameTableSize = prevTable ? ((_a = prevTable === null || prevTable === void 0 ? void 0 : prevTable.rows[0]) === null || _a === void 0 ? void 0 : _a.length) === ((_b = topRowTable === null || topRowTable === void 0 ? void 0 : topRowTable[0]) === null || _b === void 0 ? void 0 : _b.length) : false;
52
+ var isSameSection = prevTable ? prevTable.sectionIndex === sectionIndexByTable.get(table) : false;
53
+ var isSharedHeader = !!topRowTable && table.getTitle() === '' && isSameTableSize && isSameSection;
54
+ // some tables will be in the same section directly below another table and expected to have the same header.
55
+ if (isSharedHeader) {
56
+ topRowTable.unshift(__spreadArray([], prevTable.rows[0], true));
57
+ table.setTitle(prevTable.title);
58
+ }
59
+ var rows = (_c = headerTable !== null && headerTable !== void 0 ? headerTable : topRowTable) !== null && _c !== void 0 ? _c : [];
60
+ if (rows.length === 0)
61
+ return "continue";
62
+ tableDataArr.push({
63
+ title: title.trim(),
64
+ sectionIndex: (_d = sectionIndexByTable.get(table)) !== null && _d !== void 0 ? _d : -1,
65
+ hasHeader: Boolean(header) || isSharedHeader,
66
+ textBefore: textBefore,
67
+ textAfter: textAfter,
68
+ rows: rows.filter(function (r) { return r.length === rows[0].length; }),
69
+ });
70
+ };
71
+ // create table arrays
72
+ for (var _e = 0, tables_1 = tables; _e < tables_1.length; _e++) {
73
+ var table = tables_1[_e];
74
+ _loop_1(table);
75
+ }
76
+ return tableDataArr;
77
+ }
78
+ exports.parseForm10k = parseForm10k;
@@ -8,7 +8,7 @@ interface ReportParserArgs {
8
8
  propertyResolver?: PropertyResolver;
9
9
  keyTranslator?: Record<string, string[]>;
10
10
  }
11
- declare 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) => any;
12
12
  /**
13
13
  * Takes company facts data from the SEC and translates them to reports as json objects.
14
14
  */
@@ -24,11 +24,11 @@ export default class ReportParser {
24
24
  *
25
25
  * @param companyFactListData This is the json file contents of CIK[number].json file from the SEC website. You can find these using their API or by downloading the companyfacts.zip file: https://www.sec.gov/edgar/sec-api-documentation
26
26
  */
27
- parseReports(companyFactListData: Pick<CompanyFactListData, 'facts'>): ReportWrapper[];
27
+ parseReports(companyFactListData: Pick<CompanyFactListData, 'facts'>, usePropertyResolver?: boolean): ReportWrapper[];
28
28
  /**
29
29
  * Same as parseReports but accepts ReportRaw[] instead of CompanyFactListData
30
30
  */
31
- parseReportsFromRaw(reportsRaw: ReportRaw[]): ReportWrapper[];
31
+ parseReportsFromRaw(reportsRaw: ReportRaw[], usePropertyResolver?: boolean): ReportWrapper[];
32
32
  /**
33
33
  * Note that this includes all reports by default, not just annual and quarterly. use options.reportsToInclude to filter
34
34
  *