sec-edgar-api 0.0.5 → 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 (70) hide show
  1. package/README.md +9 -45
  2. package/build/index.d.ts +2 -7
  3. package/build/index.js +16 -8
  4. package/build/services/DocumentParser/DocumentParser.d.ts +16 -0
  5. package/build/services/DocumentParser/DocumentParser.js +22 -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 +40 -0
  21. package/build/services/DocumentParser/XMLParser.js +306 -0
  22. package/build/services/DocumentParser/index.d.ts +2 -0
  23. package/build/services/DocumentParser/index.js +4 -0
  24. package/build/services/DocumentParser/parsers/index.d.ts +9 -0
  25. package/build/services/DocumentParser/parsers/index.js +11 -0
  26. package/build/services/DocumentParser/parsers/parse-form-10k.d.ts +3 -0
  27. package/build/services/DocumentParser/parsers/parse-form-10k.js +78 -0
  28. package/build/services/DocumentParser/parsers/parse-form-13g.d.ts +8 -0
  29. package/build/services/DocumentParser/parsers/parse-form-13g.js +88 -0
  30. package/build/services/DocumentParser/parsers/parse-form-4.d.ts +8 -0
  31. package/build/services/DocumentParser/parsers/parse-form-4.js +220 -0
  32. package/build/services/ReportParser/ReportParser.d.ts +2 -2
  33. package/build/services/ReportParser/ReportParser.js +8 -4
  34. package/build/services/SecEdgarApi/RequestWrapper.d.ts +37 -0
  35. package/build/services/SecEdgarApi/RequestWrapper.js +147 -0
  36. package/build/services/SecEdgarApi/SecEdgarApi.d.ts +156 -22
  37. package/build/services/SecEdgarApi/SecEdgarApi.js +314 -32
  38. package/build/types/common.type.d.ts +12 -0
  39. package/build/types/common.type.js +2 -0
  40. package/build/types/index.d.ts +2 -0
  41. package/build/types/index.js +2 -0
  42. package/build/types/parsed-filings.type.d.ts +66 -0
  43. package/build/types/parsed-filings.type.js +2 -0
  44. package/build/types/submission.type.d.ts +19 -1
  45. package/package.json +1 -5
  46. package/build/.DS_Store +0 -0
  47. package/build/downloader.d.ts +0 -6
  48. package/build/downloader.js +0 -9
  49. package/build/services/FactFileReader/FactFileReader.d.ts +0 -30
  50. package/build/services/FactFileReader/FactFileReader.js +0 -36
  51. package/build/services/FactFileReader/index.d.ts +0 -2
  52. package/build/services/FactFileReader/index.js +0 -4
  53. package/build/services/FactsDownloader/Downloader.d.ts +0 -26
  54. package/build/services/FactsDownloader/Downloader.js +0 -102
  55. package/build/services/FactsDownloader/FactsDownloader.d.ts +0 -37
  56. package/build/services/FactsDownloader/FactsDownloader.js +0 -131
  57. package/build/services/FactsDownloader/Unzipper.d.ts +0 -40
  58. package/build/services/FactsDownloader/Unzipper.js +0 -40
  59. package/build/services/FactsDownloader/index.d.ts +0 -2
  60. package/build/services/FactsDownloader/index.js +0 -4
  61. package/build/services/SecEdgarApi/Client.d.ts +0 -44
  62. package/build/services/SecEdgarApi/Client.js +0 -104
  63. package/build/services/SecEdgarApi/Downloader.d.ts +0 -26
  64. package/build/services/SecEdgarApi/Downloader.js +0 -102
  65. package/build/services/SecEdgarApi/FactsDownloader.d.ts +0 -30
  66. package/build/services/SecEdgarApi/FactsDownloader.js +0 -124
  67. package/build/services/SecEdgarApi/SecConnector.d.ts +0 -47
  68. package/build/services/SecEdgarApi/SecConnector.js +0 -143
  69. package/build/services/SecEdgarApi/Unzipper.d.ts +0 -40
  70. package/build/services/SecEdgarApi/Unzipper.js +0 -40
package/README.md CHANGED
@@ -1,8 +1,15 @@
1
- # sec-edgar-api
1
+ # SEC Edgar API
2
2
 
3
3
  Fetch and parse earnings reports and other documents filed with the SEC using the EDGAR API.
4
4
  This package is focused on the earnings reports for stock analysis.
5
5
 
6
+ Some main data points available include:
7
+
8
+ - Earnings Reports
9
+ - Insider Transactions
10
+ - Institutional Holders
11
+ - Filing History
12
+
6
13
  ## Installation
7
14
 
8
15
  ```SH
@@ -93,7 +100,7 @@ interface ReportTranslated {
93
100
  import package contents
94
101
 
95
102
  ```TS
96
- import { factFileReader, reportParser, secEdgarApi } from 'sec-edgar-api'
103
+ import { secEdgarApi } from 'sec-edgar-api'
97
104
  ```
98
105
 
99
106
  You can fetch reports individually directly from the SEC website, (throttled to 10 requests per second)
@@ -103,38 +110,6 @@ You can fetch reports individually directly from the SEC website, (throttled to
103
110
  const reports = await secEdgarApi.getReports({ symbol: 'AAPL' })
104
111
  ```
105
112
 
106
- or download all data from the SEC website and read directly from the files so you don't have to worry about rate limiting.
107
-
108
- ```TS
109
- import { factsDownloader } from 'sec-edgar-api/downloader'
110
-
111
- const downloadDirectory = './downloads/companyfacts'
112
-
113
- // Download companyfacts directory from sec.gov (over 15GB)
114
- await factsDownloader.downloadCompanyFactsDirectory({
115
- outputDirname: downloadDirectory,
116
- onDownloadComplete: () => process.stdout.write('\n'),
117
- onChunk: ({ percentComplete, stage }) => {
118
- // Write progress bar to console
119
- const countBarsComplete = Math.ceil(percentComplete * 30)
120
- const barStr = `${'='.repeat(countBarsComplete)}${' '.repeat(30 - countBarsComplete)}`
121
- const percentStr = `${(Math.round(percentComplete * 10000) / 100).toFixed(2)}%`
122
- const statusStr = stage === 'download' ? 'Downloading...' : 'Unzipping...'
123
-
124
- process.stdout.write(`\r<${barStr}> ${percentStr} ${statusStr}`)
125
- },
126
- })
127
-
128
- // read companyfacts directory
129
- const companyFacts = factFileReader.readFactFile({
130
- companyFactsDirname: downloadDirectory,
131
- symbol: 'AAPL',
132
- })
133
-
134
- // parse reports (same return value as secEdgarApi.getReports())
135
- const reports = reportParser.parseReports(companyFacts)
136
- ```
137
-
138
113
  ## Resolvers
139
114
 
140
115
  **WARNING** Still in testing. Values may not be accurate for all companies since the properties provided in the reports differ.
@@ -170,17 +145,6 @@ Files for mapping & resolving properties:
170
145
  - Mapping properties: `src/util/key-translations.ts`
171
146
  - Resolving properties: `src/services/ReportParser.ts` (add resolvers to the `resolvers/` directory, import to `/resolver/index.ts`, and add to ReportParser.resolveAll)
172
147
 
173
- These are the scripts I used to get keys commonly used across reports, which you can use to add to `key-translations.ts`
174
-
175
- ```TS
176
- import { readAllCompanyFactFiles, getPropertyUsageCounts } from './scripts/script-helpers'
177
-
178
- const companyFactsList = readAllCompanyFactFiles(path.resolve('./downloads/companyfacts'), 10)
179
- const propertyUsageCounts = getPropertyUsageCounts(companyFactsList)
180
-
181
- fs.writeFileSync('./downloads/property-usage-counts.json', JSON.stringify(propertyUsageCounts, null, 2))
182
- ```
183
-
184
148
  ### Resources
185
149
 
186
150
  - Validate resolved values: https://finance.yahoo.com/
package/build/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import FactFileReader from './services/FactFileReader';
2
1
  import ReportParser from './services/ReportParser';
3
2
  import SecEdgarApi from './services/SecEdgarApi';
4
3
  /**
@@ -6,11 +5,6 @@ import SecEdgarApi from './services/SecEdgarApi';
6
5
  * reports as json objects.
7
6
  */
8
7
  declare const reportParser: ReportParser;
9
- /**
10
- * Reads files from the companyfacts directory (which can be downloaded
11
- * using secEdgarApi.downloadCompanyFacts()).
12
- */
13
- declare const factFileReader: FactFileReader;
14
8
  /**
15
9
  * Gets company reports and filings from the SEC EDGAR API. Requests are
16
10
  * throttled with 120ms delay between requests to avoid rate limiting.
@@ -18,4 +12,5 @@ declare const factFileReader: FactFileReader;
18
12
  * @see https://www.sec.gov/edgar/sec-api-documentation
19
13
  */
20
14
  declare const secEdgarApi: SecEdgarApi;
21
- export { reportParser, factFileReader, secEdgarApi };
15
+ export { reportParser, secEdgarApi };
16
+ export * from './types';
package/build/index.js CHANGED
@@ -1,7 +1,20 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.secEdgarApi = exports.factFileReader = exports.reportParser = void 0;
4
- var FactFileReader_1 = require("./services/FactFileReader");
17
+ exports.secEdgarApi = exports.reportParser = void 0;
5
18
  var ReportParser_1 = require("./services/ReportParser");
6
19
  var SecEdgarApi_1 = require("./services/SecEdgarApi");
7
20
  /**
@@ -10,12 +23,6 @@ var SecEdgarApi_1 = require("./services/SecEdgarApi");
10
23
  */
11
24
  var reportParser = new ReportParser_1.default();
12
25
  exports.reportParser = reportParser;
13
- /**
14
- * Reads files from the companyfacts directory (which can be downloaded
15
- * using secEdgarApi.downloadCompanyFacts()).
16
- */
17
- var factFileReader = new FactFileReader_1.default();
18
- exports.factFileReader = factFileReader;
19
26
  /**
20
27
  * Gets company reports and filings from the SEC EDGAR API. Requests are
21
28
  * throttled with 120ms delay between requests to avoid rate limiting.
@@ -24,3 +31,4 @@ exports.factFileReader = factFileReader;
24
31
  */
25
32
  var secEdgarApi = new SecEdgarApi_1.default();
26
33
  exports.secEdgarApi = secEdgarApi;
34
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,16 @@
1
+ import { InsiderTransaction, XMLParams } from '../../types';
2
+ import XMLParser from './XMLParser';
3
+ import parsers from './parsers';
4
+ interface DocumentParserArgs {
5
+ parser?: XMLParser;
6
+ parsersByName?: typeof parsers;
7
+ }
8
+ export default class DocumentParser {
9
+ private readonly parser;
10
+ private readonly parsersByName;
11
+ constructor(args?: DocumentParserArgs);
12
+ parseInsiderTransactions(params: XMLParams): InsiderTransaction[];
13
+ parseHolders(params: XMLParams): import("../../types").Holder[];
14
+ parseEarningsTables(params: XMLParams): import("../../types").TableData[];
15
+ }
16
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var XMLParser_1 = require("./XMLParser");
4
+ var parsers_1 = require("./parsers");
5
+ var DocumentParser = /** @class */ (function () {
6
+ function DocumentParser(args) {
7
+ var _a = args !== null && args !== void 0 ? args : {}, _b = _a.parser, parser = _b === void 0 ? new XMLParser_1.default() : _b, _c = _a.parsersByName, parsersByName = _c === void 0 ? parsers_1.default : _c;
8
+ this.parser = parser;
9
+ this.parsersByName = parsersByName;
10
+ }
11
+ DocumentParser.prototype.parseInsiderTransactions = function (params) {
12
+ return this.parsersByName.parseForm4(params, this.parser);
13
+ };
14
+ DocumentParser.prototype.parseHolders = function (params) {
15
+ return this.parsersByName.parseForm13g(params, this.parser);
16
+ };
17
+ DocumentParser.prototype.parseEarningsTables = function (params) {
18
+ return this.parsersByName.parseForm10k(params, this.parser);
19
+ };
20
+ return DocumentParser;
21
+ }());
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
+ }