sec-edgar-api 0.0.6 → 0.1.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 (66) hide show
  1. package/README.md +2 -0
  2. package/build/index.js +5 -1
  3. package/build/services/Client/Client.d.ts +2 -1
  4. package/build/services/Client/index.js +5 -1
  5. package/build/services/DocumentParser/DocumentParser.d.ts +1 -0
  6. package/build/services/DocumentParser/DocumentParser.js +3 -0
  7. package/build/services/DocumentParser/XMLNode/ColNode.d.ts +18 -0
  8. package/build/services/DocumentParser/XMLNode/ColNode.js +74 -0
  9. package/build/services/DocumentParser/XMLNode/DocumentNode.d.ts +3 -0
  10. package/build/services/DocumentParser/XMLNode/DocumentNode.js +27 -0
  11. package/build/services/DocumentParser/XMLNode/HRNode.d.ts +3 -0
  12. package/build/services/DocumentParser/XMLNode/HRNode.js +27 -0
  13. package/build/services/DocumentParser/XMLNode/NonTableNode.d.ts +3 -0
  14. package/build/services/DocumentParser/XMLNode/NonTableNode.js +27 -0
  15. package/build/services/DocumentParser/XMLNode/RowNode.d.ts +30 -0
  16. package/build/services/DocumentParser/XMLNode/RowNode.js +177 -0
  17. package/build/services/DocumentParser/XMLNode/TableNode.d.ts +20 -0
  18. package/build/services/DocumentParser/XMLNode/TableNode.js +132 -0
  19. package/build/services/DocumentParser/XMLNode/XMLNode.d.ts +37 -0
  20. package/build/services/DocumentParser/XMLNode/XMLNode.js +154 -0
  21. package/build/services/DocumentParser/XMLParser.d.ts +15 -0
  22. package/build/services/DocumentParser/XMLParser.js +180 -52
  23. package/build/services/DocumentParser/parsers/index.d.ts +2 -0
  24. package/build/services/DocumentParser/parsers/index.js +2 -0
  25. package/build/services/DocumentParser/parsers/parse-form-10k.d.ts +3 -0
  26. package/build/services/DocumentParser/parsers/parse-form-10k.js +78 -0
  27. package/build/services/ReportParser/ReportParser.d.ts +3 -3
  28. package/build/services/ReportParser/ReportParser.js +8 -4
  29. package/build/services/ReportParser/ReportTranslatedProxy.d.ts +1 -1
  30. package/build/services/ReportParser/ReportWrapper.js +2 -1
  31. package/build/services/ReportParser/resolvers/helpers.d.ts +1 -1
  32. package/build/services/SecEdgarApi/RequestWrapper.d.ts +19 -12
  33. package/build/services/SecEdgarApi/RequestWrapper.js +52 -38
  34. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +22 -9
  35. package/build/services/SecEdgarApi/SecEdgarApi.js +48 -25
  36. package/build/services/SecEdgarApi/Throttler.js +1 -1
  37. package/build/services/SecEdgarApi/index.js +5 -1
  38. package/build/types/index.js +5 -1
  39. package/build/types/parsed-filings.type.d.ts +11 -3
  40. package/build/types/report-raw.type.d.ts +3 -3
  41. package/package.json +1 -1
  42. package/build/.DS_Store +0 -0
  43. package/build/downloader.d.ts +0 -6
  44. package/build/downloader.js +0 -9
  45. package/build/services/FactFileReader/FactFileReader.d.ts +0 -30
  46. package/build/services/FactFileReader/FactFileReader.js +0 -36
  47. package/build/services/FactFileReader/index.d.ts +0 -2
  48. package/build/services/FactFileReader/index.js +0 -4
  49. package/build/services/FactsDownloader/Downloader.d.ts +0 -26
  50. package/build/services/FactsDownloader/Downloader.js +0 -102
  51. package/build/services/FactsDownloader/FactsDownloader.d.ts +0 -37
  52. package/build/services/FactsDownloader/FactsDownloader.js +0 -131
  53. package/build/services/FactsDownloader/Unzipper.d.ts +0 -40
  54. package/build/services/FactsDownloader/Unzipper.js +0 -40
  55. package/build/services/FactsDownloader/index.d.ts +0 -2
  56. package/build/services/FactsDownloader/index.js +0 -4
  57. package/build/services/SecEdgarApi/Client.d.ts +0 -44
  58. package/build/services/SecEdgarApi/Client.js +0 -104
  59. package/build/services/SecEdgarApi/Downloader.d.ts +0 -26
  60. package/build/services/SecEdgarApi/Downloader.js +0 -102
  61. package/build/services/SecEdgarApi/FactsDownloader.d.ts +0 -30
  62. package/build/services/SecEdgarApi/FactsDownloader.js +0 -124
  63. package/build/services/SecEdgarApi/SecConnector.d.ts +0 -47
  64. package/build/services/SecEdgarApi/SecConnector.js +0 -143
  65. package/build/services/SecEdgarApi/Unzipper.d.ts +0 -40
  66. package/build/services/SecEdgarApi/Unzipper.js +0 -40
package/README.md CHANGED
@@ -9,6 +9,8 @@ Some main data points available include:
9
9
  - Insider Transactions
10
10
  - Institutional Holders
11
11
  - Filing History
12
+ - Directors & Executives
13
+ - Executive Compensation
12
14
 
13
15
  ## Installation
14
16
 
package/build/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { ClientRequest, IncomingMessage, RequestOptions } from 'http';
3
- declare type Primitive = string | number | boolean | null | undefined;
4
+ type Primitive = string | number | boolean | null | undefined;
4
5
  interface HttpClient {
5
6
  request: (options: string | URL | RequestOptions, callback?: (res: IncomingMessage) => void) => ClientRequest;
6
7
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -11,5 +11,6 @@ export default class DocumentParser {
11
11
  constructor(args?: DocumentParserArgs);
12
12
  parseInsiderTransactions(params: XMLParams): InsiderTransaction[];
13
13
  parseHolders(params: XMLParams): import("../../types").Holder[];
14
+ parseEarningsTables(params: XMLParams): import("../../types").TableData[];
14
15
  }
15
16
  export {};
@@ -14,6 +14,9 @@ var DocumentParser = /** @class */ (function () {
14
14
  DocumentParser.prototype.parseHolders = function (params) {
15
15
  return this.parsersByName.parseForm13g(params, this.parser);
16
16
  };
17
+ DocumentParser.prototype.parseEarningsTables = function (params) {
18
+ return this.parsersByName.parseForm10k(params, this.parser);
19
+ };
17
20
  return DocumentParser;
18
21
  }());
19
22
  exports.default = DocumentParser;
@@ -0,0 +1,18 @@
1
+ import { RowNode } from './RowNode';
2
+ import { XMLNode } from './XMLNode';
3
+ export declare class ColNode extends XMLNode {
4
+ private colSpan;
5
+ private index;
6
+ private topSiblings;
7
+ private bottomSiblings;
8
+ setIndex(index: number): void;
9
+ getIndex(): number;
10
+ getParent(): RowNode;
11
+ addTopSibling(node: ColNode): void;
12
+ addBottomSibling(node: ColNode): void;
13
+ getTopSiblings(): ColNode[];
14
+ getBottomSiblings(): ColNode[];
15
+ getNextSibling(): ColNode | null;
16
+ getPreviousSibling(): ColNode | null;
17
+ getColSpan(): number;
18
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ColNode = void 0;
19
+ var XMLNode_1 = require("./XMLNode");
20
+ var ColNode = /** @class */ (function (_super) {
21
+ __extends(ColNode, _super);
22
+ function ColNode() {
23
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
+ _this.colSpan = null;
25
+ _this.index = null;
26
+ _this.topSiblings = [];
27
+ _this.bottomSiblings = [];
28
+ return _this;
29
+ }
30
+ ColNode.prototype.setIndex = function (index) {
31
+ this.index = index;
32
+ };
33
+ ColNode.prototype.getIndex = function () {
34
+ var _a;
35
+ return (_a = this.index) !== null && _a !== void 0 ? _a : -1;
36
+ };
37
+ ColNode.prototype.getParent = function () {
38
+ return _super.prototype.getParent.call(this);
39
+ };
40
+ ColNode.prototype.addTopSibling = function (node) {
41
+ this.topSiblings.push(node);
42
+ if (!node.getBottomSiblings().includes(this)) {
43
+ node.addBottomSibling(this);
44
+ }
45
+ };
46
+ ColNode.prototype.addBottomSibling = function (node) {
47
+ this.bottomSiblings.push(node);
48
+ if (!node.getTopSiblings().includes(this)) {
49
+ node.addTopSibling(this);
50
+ }
51
+ };
52
+ ColNode.prototype.getTopSiblings = function () {
53
+ return this.topSiblings;
54
+ };
55
+ ColNode.prototype.getBottomSiblings = function () {
56
+ return this.bottomSiblings;
57
+ };
58
+ ColNode.prototype.getNextSibling = function () {
59
+ return _super.prototype.getNextSibling.call(this);
60
+ };
61
+ ColNode.prototype.getPreviousSibling = function () {
62
+ return _super.prototype.getPreviousSibling.call(this);
63
+ };
64
+ ColNode.prototype.getColSpan = function () {
65
+ var _a;
66
+ if (this.colSpan)
67
+ return this.colSpan;
68
+ var colSpan = Number((_a = this.getAttributes().colspan) !== null && _a !== void 0 ? _a : 1);
69
+ this.colSpan = colSpan;
70
+ return colSpan;
71
+ };
72
+ return ColNode;
73
+ }(XMLNode_1.XMLNode));
74
+ exports.ColNode = ColNode;
@@ -0,0 +1,3 @@
1
+ import { XMLNode } from './XMLNode';
2
+ export declare class DocumentNode extends XMLNode {
3
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.DocumentNode = void 0;
19
+ var XMLNode_1 = require("./XMLNode");
20
+ var DocumentNode = /** @class */ (function (_super) {
21
+ __extends(DocumentNode, _super);
22
+ function DocumentNode() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ return DocumentNode;
26
+ }(XMLNode_1.XMLNode));
27
+ exports.DocumentNode = DocumentNode;
@@ -0,0 +1,3 @@
1
+ import { XMLNode } from './XMLNode';
2
+ export declare class HRNode extends XMLNode {
3
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.HRNode = void 0;
19
+ var XMLNode_1 = require("./XMLNode");
20
+ var HRNode = /** @class */ (function (_super) {
21
+ __extends(HRNode, _super);
22
+ function HRNode() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ return HRNode;
26
+ }(XMLNode_1.XMLNode));
27
+ exports.HRNode = HRNode;
@@ -0,0 +1,3 @@
1
+ import { XMLNode } from './XMLNode';
2
+ export declare class NonTableNode extends XMLNode {
3
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NonTableNode = void 0;
19
+ var XMLNode_1 = require("./XMLNode");
20
+ var NonTableNode = /** @class */ (function (_super) {
21
+ __extends(NonTableNode, _super);
22
+ function NonTableNode() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ return NonTableNode;
26
+ }(XMLNode_1.XMLNode));
27
+ exports.NonTableNode = NonTableNode;
@@ -0,0 +1,30 @@
1
+ import { ColNode } from './ColNode';
2
+ import { TableNode } from './TableNode';
3
+ import { XMLNode } from './XMLNode';
4
+ export declare class RowNode extends XMLNode {
5
+ private isHeader;
6
+ private isEmpty;
7
+ getIsEmpty(): boolean;
8
+ clone(): RowNode;
9
+ setIsHeader(isHeader: boolean): void;
10
+ getIsHeader(): boolean;
11
+ getChildren(): ColNode[];
12
+ getParent(): TableNode;
13
+ getNextSibling(): RowNode | null;
14
+ getPreviousSibling(): RowNode | null;
15
+ /**
16
+ * Uses the columns in this row to build a table. Each column is also an array since cols can touch
17
+ * multiple other cells on the top and bottom due to colspan.
18
+ *
19
+ * ```ts
20
+ * const returnExample = [
21
+ * [ [ColNode, ColNode], [ColNode], [ColNode, ColNode, ColNode] ]
22
+ * [ [ColNode], [ColNode], [ColNode] ], // this row
23
+ * [ [ColNode], [ColNode], [ColNode, ColNode] ],
24
+ * ]
25
+ * ```
26
+ */
27
+ getTableFromCols(): ColNode[][][];
28
+ toTable(parseValues?: boolean): (string | number | null)[][];
29
+ toArray(parseValues?: boolean): (string | number | null)[];
30
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RowNode = void 0;
19
+ var ColNode_1 = require("./ColNode");
20
+ var XMLNode_1 = require("./XMLNode");
21
+ var RowNode = /** @class */ (function (_super) {
22
+ __extends(RowNode, _super);
23
+ function RowNode() {
24
+ var _this = _super !== null && _super.apply(this, arguments) || this;
25
+ _this.isHeader = false;
26
+ _this.isEmpty = null;
27
+ return _this;
28
+ }
29
+ RowNode.prototype.getIsEmpty = function () {
30
+ if (this.isEmpty !== null)
31
+ return this.isEmpty;
32
+ this.isEmpty = this.toArray().filter(Boolean).length === 0;
33
+ return Boolean(this.isEmpty);
34
+ };
35
+ RowNode.prototype.clone = function () {
36
+ var clone = new RowNode({ attributesStr: this.getAttributesStr(), path: this.getPath() });
37
+ clone.setText(this.getText());
38
+ this.getChildren().forEach(function (child) {
39
+ var childNew = new ColNode_1.ColNode({ attributesStr: child.getAttributesStr(), path: child.getPath() });
40
+ var prevChild = clone.getChildren()[clone.getChildren().length - 1];
41
+ childNew.setText(child.getText());
42
+ childNew.setIndex(child.getIndex());
43
+ prevChild === null || prevChild === void 0 ? void 0 : prevChild.setNextSibling(childNew);
44
+ clone.addChild(childNew);
45
+ });
46
+ return clone;
47
+ };
48
+ RowNode.prototype.setIsHeader = function (isHeader) {
49
+ this.isHeader = isHeader;
50
+ };
51
+ RowNode.prototype.getIsHeader = function () {
52
+ return this.isHeader;
53
+ };
54
+ RowNode.prototype.getChildren = function () {
55
+ return _super.prototype.getChildren.call(this);
56
+ };
57
+ RowNode.prototype.getParent = function () {
58
+ return _super.prototype.getParent.call(this);
59
+ };
60
+ RowNode.prototype.getNextSibling = function () {
61
+ return _super.prototype.getNextSibling.call(this);
62
+ };
63
+ RowNode.prototype.getPreviousSibling = function () {
64
+ return _super.prototype.getPreviousSibling.call(this);
65
+ };
66
+ /**
67
+ * Uses the columns in this row to build a table. Each column is also an array since cols can touch
68
+ * multiple other cells on the top and bottom due to colspan.
69
+ *
70
+ * ```ts
71
+ * const returnExample = [
72
+ * [ [ColNode, ColNode], [ColNode], [ColNode, ColNode, ColNode] ]
73
+ * [ [ColNode], [ColNode], [ColNode] ], // this row
74
+ * [ [ColNode], [ColNode], [ColNode, ColNode] ],
75
+ * ]
76
+ * ```
77
+ */
78
+ RowNode.prototype.getTableFromCols = function () {
79
+ var tableRowCols = [];
80
+ var colIndexRanges = this.getChildren().map(function (col) { return [col.getIndex(), col.getIndex() + col.getColSpan()]; });
81
+ for (var _i = 0, _a = this.getParent().getChildren(); _i < _a.length; _i++) {
82
+ var row = _a[_i];
83
+ var rowCols = colIndexRanges.map(function () { return []; });
84
+ for (var _b = 0, _c = row.getChildren(); _b < _c.length; _b++) {
85
+ var col = _c[_b];
86
+ var _d = [col.getIndex(), col.getIndex() + col.getColSpan()], indexStart = _d[0], indexEnd = _d[1];
87
+ for (var i = 0; i < colIndexRanges.length; i++) {
88
+ var _e = colIndexRanges[i], boundaryStart = _e[0], boundaryEnd = _e[1];
89
+ if (indexEnd <= boundaryStart || indexStart >= boundaryEnd)
90
+ continue;
91
+ rowCols[i].push(col);
92
+ }
93
+ }
94
+ tableRowCols.push(rowCols);
95
+ }
96
+ return tableRowCols;
97
+ };
98
+ RowNode.prototype.toTable = function (parseValues) {
99
+ var _a, _b, _c;
100
+ if (parseValues === void 0) { parseValues = true; }
101
+ var table = this.getTableFromCols();
102
+ var tableTextArr = [];
103
+ var headerRowIndex = (_a = this.getParent().getHeaderRowIndex()) !== null && _a !== void 0 ? _a : -1;
104
+ for (var rowIndex = 0; rowIndex < table.length; rowIndex++) {
105
+ var row = table[rowIndex];
106
+ var colTextArr = [];
107
+ for (var _i = 0, row_1 = row; _i < row_1.length; _i++) {
108
+ var colArr = row_1[_i];
109
+ var colText = colArr.reduce(function (acc, col) { return "".concat(acc, " ").concat(col.getText()); }, '');
110
+ // skip rows that are titles within the table body
111
+ var isTitleRow = colArr.length === 1 &&
112
+ colArr[0].getColSpan() >= this.getChildren().length &&
113
+ rowIndex > headerRowIndex;
114
+ if (isTitleRow)
115
+ continue;
116
+ if (!parseValues) {
117
+ colTextArr.push(colText.trim());
118
+ continue;
119
+ }
120
+ // sometimes there is a rogue percent sign that is not in a column, so we need to check the next column
121
+ var nextCol = (_b = colArr[colArr.length - 1]) === null || _b === void 0 ? void 0 : _b.getNextSibling();
122
+ var isMissingPercentSign = (nextCol === null || nextCol === void 0 ? void 0 : nextCol.getText().includes('%')) && nextCol.parseValue() === null;
123
+ var isMissingParenthesis = (nextCol === null || nextCol === void 0 ? void 0 : nextCol.getText().includes(')')) && colText.includes('(') && !colText.includes(')');
124
+ var colTextTrimmed = isMissingParenthesis ? "".concat(colText.trim(), ")") : colText.trim();
125
+ colTextTrimmed = isMissingPercentSign ? "".concat(colText.trim(), "%") : colText.trim();
126
+ colTextTrimmed = this.parseValue(colTextTrimmed);
127
+ colTextTrimmed =
128
+ typeof colTextTrimmed === 'string' ? colTextTrimmed.replace(/\s+/g, ' ') : colTextTrimmed;
129
+ colTextArr.push(colTextTrimmed);
130
+ }
131
+ tableTextArr.push(colTextArr);
132
+ }
133
+ if (!parseValues)
134
+ return tableTextArr;
135
+ var emptyColIndexes = new Set();
136
+ cols: for (var colIndex = 0; colIndex < tableTextArr[0].length; colIndex++) {
137
+ for (var rowIndex = 1; rowIndex < tableTextArr.length; rowIndex++) {
138
+ if (Boolean(tableTextArr[rowIndex][colIndex]) && tableTextArr[rowIndex][colIndex] !== '%') {
139
+ continue cols;
140
+ }
141
+ }
142
+ emptyColIndexes.add(colIndex);
143
+ }
144
+ tableTextArr.forEach(function (row, i) {
145
+ tableTextArr[i] = row.filter(function (_, i) { return !emptyColIndexes.has(i); });
146
+ });
147
+ var tableTextArrFiltered = [];
148
+ for (var rowIndex = 0; rowIndex < tableTextArr.length; rowIndex++) {
149
+ var row = tableTextArr[rowIndex];
150
+ var isEmpty = !row.some(Boolean);
151
+ // if is empty before the header or empty next to another empty row, continue
152
+ if (isEmpty && (rowIndex < headerRowIndex || !((_c = tableTextArr[rowIndex - 1]) === null || _c === void 0 ? void 0 : _c.some(Boolean)))) {
153
+ continue;
154
+ }
155
+ tableTextArrFiltered.push(row);
156
+ }
157
+ return tableTextArr.filter(function (row, i) {
158
+ var rowPrev = tableTextArr[i - 1];
159
+ var isEmpty = !row.some(Boolean);
160
+ var isLast = i === tableTextArr.length - 1;
161
+ // empty rows cannot be before header, last in array, or next to another empty row
162
+ return !(isEmpty && (i < headerRowIndex || !(rowPrev === null || rowPrev === void 0 ? void 0 : rowPrev.some(Boolean)) || isLast));
163
+ });
164
+ };
165
+ RowNode.prototype.toArray = function (parseValues) {
166
+ var _this = this;
167
+ if (parseValues === void 0) { parseValues = true; }
168
+ var cols = [];
169
+ this.getChildren().forEach(function (col) {
170
+ cols.push(parseValues ? _this.parseValue(col.getText()) : col.getText());
171
+ Array.from({ length: col.getColSpan() - 1 }).forEach(function () { return cols.push(null); });
172
+ });
173
+ return cols;
174
+ };
175
+ return RowNode;
176
+ }(XMLNode_1.XMLNode));
177
+ exports.RowNode = RowNode;
@@ -0,0 +1,20 @@
1
+ import { RowNode } from './RowNode';
2
+ import { XMLNode } from './XMLNode';
3
+ export declare class TableNode extends XMLNode {
4
+ private title;
5
+ private headerRow;
6
+ getTitle(): string;
7
+ setTitle(title: string): void;
8
+ getChildren(): RowNode[];
9
+ removeTopChild(): void;
10
+ removeEmptyTopRows(): void;
11
+ prependChild(node: RowNode): void;
12
+ toArray(parseValues?: boolean): (string | number | null)[][];
13
+ setHeaderRow(row: RowNode): void;
14
+ getHeaderRowIndex(): number | null;
15
+ mergeHeader(removeMergedChildren?: boolean): RowNode | undefined;
16
+ /**
17
+ * If header row is not set, this will try to find it.
18
+ */
19
+ getHeaderRow(): RowNode;
20
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.TableNode = void 0;
19
+ var XMLNode_1 = require("./XMLNode");
20
+ var TableNode = /** @class */ (function (_super) {
21
+ __extends(TableNode, _super);
22
+ function TableNode() {
23
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
+ _this.title = null;
25
+ _this.headerRow = null;
26
+ return _this;
27
+ }
28
+ TableNode.prototype.getTitle = function () {
29
+ var _a;
30
+ return (_a = this.title) !== null && _a !== void 0 ? _a : '';
31
+ };
32
+ TableNode.prototype.setTitle = function (title) {
33
+ this.title = title;
34
+ };
35
+ TableNode.prototype.getChildren = function () {
36
+ return _super.prototype.getChildren.call(this);
37
+ };
38
+ TableNode.prototype.removeTopChild = function () {
39
+ this.removeChild(this.getChildren()[0]);
40
+ };
41
+ TableNode.prototype.removeEmptyTopRows = function () {
42
+ var _a;
43
+ while ((_a = this.getChildren()[0]) === null || _a === void 0 ? void 0 : _a.getIsEmpty()) {
44
+ this.removeChild(this.getChildren()[0]);
45
+ }
46
+ };
47
+ TableNode.prototype.prependChild = function (node) {
48
+ var prevTopChild = this.getChildren()[0];
49
+ this.getChildren().unshift(node);
50
+ if (node.getParent() !== this)
51
+ node.setParent(this);
52
+ prevTopChild === null || prevTopChild === void 0 ? void 0 : prevTopChild.setPreviousSibling(node);
53
+ var colArrTop = [];
54
+ var colArrBottom = [];
55
+ node.getChildren().forEach(function (col) {
56
+ colArrTop.push(col);
57
+ Array.from({ length: col.getColSpan() - 1 }).forEach(function () { return colArrTop.push(col); });
58
+ });
59
+ prevTopChild === null || prevTopChild === void 0 ? void 0 : prevTopChild.getChildren().forEach(function (col, i) {
60
+ colArrBottom.push(col);
61
+ Array.from({ length: col.getColSpan() - 1 }).forEach(function () { return colArrBottom.push(col); });
62
+ if (!col.getTopSiblings().includes(colArrTop[i])) {
63
+ col.addTopSibling(colArrTop[i]);
64
+ }
65
+ });
66
+ };
67
+ TableNode.prototype.toArray = function (parseValues) {
68
+ if (parseValues === void 0) { parseValues = true; }
69
+ return this.getChildren().map(function (row) { return row.toArray(parseValues); });
70
+ };
71
+ TableNode.prototype.setHeaderRow = function (row) {
72
+ this.headerRow = row;
73
+ };
74
+ TableNode.prototype.getHeaderRowIndex = function () {
75
+ var rows = this.getChildren();
76
+ // assume body index starts with row that has a non-bold number in it.
77
+ var bodyIndex = rows.findIndex(function (row) {
78
+ return row.getChildren().some(function (col) { return typeof col.parseValue() === 'number' && !col.getText().includes('}}'); });
79
+ });
80
+ var getRowData = function (row) { return row.getChildren().map(function (col) { return col.parseValue(); }); };
81
+ // if the header row is only one value, or empty, it's likely a label in the table body, so keep moving up.
82
+ var headerIndex = bodyIndex - 1;
83
+ while (rows[headerIndex] && getRowData(rows[headerIndex]).filter(Boolean).length <= 1 && headerIndex >= 0) {
84
+ headerIndex--;
85
+ }
86
+ return headerIndex >= 0 ? headerIndex : null;
87
+ };
88
+ TableNode.prototype.mergeHeader = function (removeMergedChildren) {
89
+ var _a, _b, _c;
90
+ if (removeMergedChildren === void 0) { removeMergedChildren = true; }
91
+ var headerRowIndex = (_a = this.getHeaderRowIndex()) !== null && _a !== void 0 ? _a : -1;
92
+ var headerRow = (_b = this.getChildren()[headerRowIndex]) !== null && _b !== void 0 ? _b : null;
93
+ if (!headerRow)
94
+ return;
95
+ var table = headerRow.toTable(false);
96
+ var headerRowCols = headerRow.getChildren();
97
+ // start from the row above the header row to merge.
98
+ for (var rowIndex = headerRowIndex - 1; rowIndex >= 0; rowIndex--) {
99
+ var curRow = table[rowIndex];
100
+ // go through each header column to merge with the one above.
101
+ for (var colIndex = 0; colIndex < curRow.length; colIndex++) {
102
+ if (table[headerRowIndex][colIndex] === null)
103
+ continue;
104
+ // if prev header col is empty, get nearest to the left.
105
+ var colIndexCur = colIndex;
106
+ while (!curRow[colIndexCur] && colIndexCur >= 0) {
107
+ colIndexCur--;
108
+ }
109
+ // if the value is empty, continue.
110
+ var colValue = (_c = curRow[colIndexCur]) !== null && _c !== void 0 ? _c : null;
111
+ if (!colValue || !this.parseValue("".concat(colValue)))
112
+ continue;
113
+ headerRowCols[colIndex].setText("".concat(colValue, " ").concat(headerRowCols[colIndex].getText()).trim());
114
+ }
115
+ }
116
+ if (removeMergedChildren) {
117
+ while (this.getChildren()[0] !== headerRow && this.getChildren().length > 0) {
118
+ this.removeTopChild();
119
+ }
120
+ }
121
+ return headerRow;
122
+ };
123
+ /**
124
+ * If header row is not set, this will try to find it.
125
+ */
126
+ TableNode.prototype.getHeaderRow = function () {
127
+ var _a, _b, _c;
128
+ return (_c = (_a = this.headerRow) !== null && _a !== void 0 ? _a : this.getChildren()[(_b = this.getHeaderRowIndex()) !== null && _b !== void 0 ? _b : -1]) !== null && _c !== void 0 ? _c : null;
129
+ };
130
+ return TableNode;
131
+ }(XMLNode_1.XMLNode));
132
+ exports.TableNode = TableNode;
@@ -0,0 +1,37 @@
1
+ interface XMLNodeArgs {
2
+ path?: string;
3
+ attributesStr?: string;
4
+ }
5
+ interface GetSiblingsParams {
6
+ dir: 'previous' | 'next';
7
+ stopAtType?: new () => XMLNode;
8
+ includeStopAtType?: boolean;
9
+ }
10
+ export declare class XMLNode {
11
+ private parent;
12
+ private previousSibling;
13
+ private nextSibling;
14
+ private children;
15
+ private text;
16
+ private attributesStr;
17
+ private path;
18
+ constructor(args?: XMLNodeArgs);
19
+ getSiblings(params: GetSiblingsParams): XMLNode[];
20
+ extractBold(str?: string): string;
21
+ parseValue(str?: string | null): string | number | null;
22
+ setPreviousSibling(node: XMLNode | null): void;
23
+ setNextSibling(node: XMLNode | null): void;
24
+ removeChild(node: XMLNode): void;
25
+ setParent(node: XMLNode | null): void;
26
+ getNextSibling(): XMLNode | null;
27
+ getPreviousSibling(): XMLNode | null;
28
+ getParent(): XMLNode | null;
29
+ getAttributes(): Record<string, string>;
30
+ getAttributesStr(): string;
31
+ getChildren(): XMLNode[];
32
+ addChild(node: XMLNode): void;
33
+ getText(): string;
34
+ setText(text: string): void;
35
+ getPath(): string;
36
+ }
37
+ export {};