sec-edgar-api 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,14 @@
1
1
  export default class XMLParser {
2
2
  private readonly selfEnclosingTags;
3
+ private readonly textSelectStrategy;
4
+ private readonly tagsToIgnore;
5
+ private readonly textConcatDivider;
6
+ constructor(params?: {
7
+ textSelectStrategy?: 'useFirst' | 'useLast' | 'concatenate';
8
+ textConcatDivider?: string;
9
+ });
3
10
  mapAttributes(attributes: string[]): Map<string, string>;
4
- parse(xml: string): Record<string, unknown>;
11
+ parse(xml: string): any;
5
12
  iterateXML(params: {
6
13
  xml: string;
7
14
  onOpenTag?: (tagName: string, attributes: string[], isSelfEnclosing: boolean) => void;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var XMLParser = /** @class */ (function () {
4
- function XMLParser() {
4
+ function XMLParser(params) {
5
5
  this.selfEnclosingTags = new Set([
6
6
  '!doctype',
7
7
  '?xml',
@@ -14,6 +14,10 @@ var XMLParser = /** @class */ (function () {
14
14
  'filename',
15
15
  'description',
16
16
  ]);
17
+ this.tagsToIgnore = new Set(['script', '?xml']);
18
+ var _a = params !== null && params !== void 0 ? params : {}, _b = _a.textSelectStrategy, textSelectStrategy = _b === void 0 ? 'useFirst' : _b, _c = _a.textConcatDivider, textConcatDivider = _c === void 0 ? '<>' : _c;
19
+ this.textSelectStrategy = textSelectStrategy;
20
+ this.textConcatDivider = textConcatDivider;
17
21
  }
18
22
  XMLParser.prototype.mapAttributes = function (attributes) {
19
23
  var attributesMap = new Map();
@@ -25,6 +29,7 @@ var XMLParser = /** @class */ (function () {
25
29
  });
26
30
  return attributesMap;
27
31
  };
32
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
33
  XMLParser.prototype.parse = function (xml) {
29
34
  var _this = this;
30
35
  var currentObj = {};
@@ -35,7 +40,7 @@ var XMLParser = /** @class */ (function () {
35
40
  var newObj = {};
36
41
  var obj = currentObj;
37
42
  var isComment = tagName.startsWith('!--');
38
- if (isComment || tagName === '?xml')
43
+ if (isComment || _this.tagsToIgnore.has(tagName.toLowerCase()))
39
44
  return;
40
45
  if (obj[tagName] === undefined) {
41
46
  obj[tagName] = newObj;
@@ -60,10 +65,24 @@ var XMLParser = /** @class */ (function () {
60
65
  if (!textTrimmed)
61
66
  return;
62
67
  var obj = currentObj;
63
- obj['#text'] = textTrimmed;
68
+ switch (_this.textSelectStrategy) {
69
+ case 'useFirst':
70
+ if (obj['#text'])
71
+ return;
72
+ obj['#text'] = textTrimmed;
73
+ break;
74
+ case 'useLast':
75
+ obj['#text'] = textTrimmed;
76
+ break;
77
+ case 'concatenate':
78
+ obj['#text'] = obj['#text']
79
+ ? "".concat(obj['#text'], " ").concat(_this.textConcatDivider, " ").concat(textTrimmed)
80
+ : textTrimmed;
81
+ break;
82
+ }
64
83
  },
65
- onCloseTag: function () {
66
- if (objPath.length === 1)
84
+ onCloseTag: function (tagName) {
85
+ if (objPath.length === 1 || _this.tagsToIgnore.has(tagName.toLowerCase()))
67
86
  return;
68
87
  objPath.pop();
69
88
  currentObj = objPath[objPath.length - 1];
@@ -1,51 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseCompanies = void 0;
4
- var HtmlTableExtractor_1 = require("../../HtmlTableExtractor");
4
+ var XMLParser_1 = require("../XMLParser");
5
5
  function parseCompanies(params) {
6
- var _a, _b, _c, _d;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
7
7
  var xml = params.xml;
8
- var parser = new HtmlTableExtractor_1.default();
9
- var tables = parser.extractTables(xml, {
10
- stripHtml: true,
11
- tagsToExclude: ['sup'],
12
- stripParenthesis: true,
13
- removeEmptyColumns: false,
14
- getHeaderRowIndex: function (data) {
15
- return data.rows.findIndex(function (row) {
16
- var isNotEmptyRow = row.some(function (cell) { return cell.html.replace(/<.*?>/g, '').replace(/&.*?;/g, '').replace(/\s/g, '').length > 0; });
17
- return isNotEmptyRow;
18
- });
19
- },
20
- });
21
- var header = ['cik', 'company_name', 'state_country'];
22
- var table = tables.find(function (t) { return t.rows.some(function (r) { return r.some(function (c) { return c.html.includes('CIK'); }); }); });
8
+ var parser = new XMLParser_1.default({ textSelectStrategy: 'concatenate', textConcatDivider: '<>' });
9
+ var result = parser.parse(xml);
10
+ var body = (_b = (_a = result.html) === null || _a === void 0 ? void 0 : _a.body) !== null && _b !== void 0 ? _b : {};
11
+ var bodyDivs = Array.isArray(body.div) ? body.div : [body.div].filter(Boolean);
12
+ var contentDiv = (_c = bodyDivs.find(function (d) { return d && typeof d === 'object' && d['@_id'] === 'contentDiv'; })) !== null && _c !== void 0 ? _c : {};
13
+ var tableDivs = Array.isArray(contentDiv.div) ? contentDiv.div : [contentDiv.div].filter(Boolean);
14
+ var tableDiv = (_d = tableDivs.find(function (d) { return d && typeof d === 'object' && d['@_id'] === 'seriesDiv'; })) !== null && _d !== void 0 ? _d : {};
15
+ var rows = (_j = (_f = (_e = tableDiv.table) === null || _e === void 0 ? void 0 : _e.tr) !== null && _f !== void 0 ? _f : (_h = (_g = tableDiv.table) === null || _g === void 0 ? void 0 : _g.tbody) === null || _h === void 0 ? void 0 : _h.tr) !== null && _j !== void 0 ? _j : [];
16
+ rows = (Array.isArray(rows) ? rows : [rows])
17
+ .filter(function (r) { return r === null || r === void 0 ? void 0 : r.td; })
18
+ .map(function (r) { return (Array.isArray(r.td) ? r.td : [r.td]).filter(Boolean); });
23
19
  var items = [];
24
- for (var _i = 0, _e = (_a = table === null || table === void 0 ? void 0 : table.rows) !== null && _a !== void 0 ? _a : []; _i < _e.length; _i++) {
25
- var row = _e[_i];
26
- if ((_b = row[0]) === null || _b === void 0 ? void 0 : _b.isHeaderRowCell)
20
+ for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
21
+ var row = rows_1[_i];
22
+ var cik = Number((_l = (_k = row[0]) === null || _k === void 0 ? void 0 : _k.a) === null || _l === void 0 ? void 0 : _l['#text']) || 0;
23
+ if (!cik)
27
24
  continue;
28
- var item = {
29
- cik: 0,
30
- companyName: '',
31
- stateOrCountry: '',
32
- };
33
- for (var _f = 0, row_1 = row; _f < row_1.length; _f++) {
34
- var cell = row_1[_f];
35
- var colName = header[cell.colIndex];
36
- switch (colName) {
37
- case 'cik':
38
- item.cik = Number(cell.valueParsed) || 0;
39
- break;
40
- case 'company_name':
41
- item.companyName = String(((_d = (_c = cell.html.split('>')[1]) === null || _c === void 0 ? void 0 : _c.split('<')[0]) === null || _d === void 0 ? void 0 : _d.split('/')[0]) || cell.valueParsed).trim();
42
- break;
43
- case 'state_country':
44
- item.stateOrCountry = String(cell.valueParsed || '');
45
- break;
46
- }
47
- }
48
- items.push(item);
25
+ var row1Parts = (_o = (((_m = row[1]) === null || _m === void 0 ? void 0 : _m['#text']) || '').split('<>')) !== null && _o !== void 0 ? _o : [];
26
+ var sic = Number((_q = (_p = row[1]) === null || _p === void 0 ? void 0 : _p.a) === null || _q === void 0 ? void 0 : _q['#text']) || null;
27
+ var companyName = row1Parts[0].trim();
28
+ var sicDescription = sic ? ((_r = row1Parts.pop()) === null || _r === void 0 ? void 0 : _r.replace('-', '').trim()) || null : null;
29
+ var stateOrCountry = ((_t = (_s = row[2]) === null || _s === void 0 ? void 0 : _s.a) === null || _t === void 0 ? void 0 : _t['#text']) || null;
30
+ items.push({ cik: cik, sic: sic, sicDescription: sicDescription, companyName: companyName, stateOrCountry: stateOrCountry });
49
31
  }
50
32
  return { items: items };
51
33
  }
@@ -65,6 +65,7 @@ function parseCurrentFilingsXbrl(params) {
65
65
  case 'item': {
66
66
  result.items.push({
67
67
  title: '',
68
+ url: '',
68
69
  companyName: '',
69
70
  cikNumber: 0,
70
71
  link: '',
@@ -99,6 +100,13 @@ function parseCurrentFilingsXbrl(params) {
99
100
  }
100
101
  },
101
102
  });
103
+ // add url to each filing
104
+ result.items.forEach(function (item) {
105
+ var cikNumber = item.cikNumber, accessionNumber = item.accessionNumber;
106
+ var accessionNoHyphen = accessionNumber.replace(/-/g, '');
107
+ var filePath = "".concat(Number(cikNumber), "/").concat(accessionNoHyphen, "/").concat(accessionNumber, ".txt");
108
+ item.url = "https://www.sec.gov/Archives/edgar/data/".concat(filePath);
109
+ });
102
110
  return result;
103
111
  }
104
112
  exports.parseCurrentFilingsXbrl = parseCurrentFilingsXbrl;
@@ -19,8 +19,6 @@ export default class ReportResolvable {
19
19
  constructor(args: {
20
20
  report: Record<string, string | number | null | boolean>;
21
21
  calculationMap?: CalculationMap;
22
- /** Used for member facts */
23
- pathSeparator?: string;
24
22
  });
25
23
  getMap(): CalculationMap;
26
24
  clearCache(): void;
@@ -336,6 +336,8 @@ export default class SecEdgarApi {
336
336
  }>;
337
337
  /**
338
338
  * Search for companies from by name, sic code, or state.
339
+ *
340
+ * example at https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&owner=exclude&&start=0&count=100&hidefilings=0&company=Apple&match=contains
339
341
  */
340
342
  searchCompanies(params: SearchCompaniesParams): Promise<{
341
343
  items: import("../../types").CompanySearchResult[];
@@ -701,6 +701,8 @@ var SecEdgarApi = /** @class */ (function () {
701
701
  };
702
702
  /**
703
703
  * Search for companies from by name, sic code, or state.
704
+ *
705
+ * example at https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&owner=exclude&&start=0&count=100&hidefilings=0&company=Apple&match=contains
704
706
  */
705
707
  SecEdgarApi.prototype.searchCompanies = function (params) {
706
708
  return __awaiter(this, void 0, void 0, function () {
@@ -1,5 +1,7 @@
1
1
  export interface CompanySearchResult {
2
2
  cik: number;
3
+ sic: number | null;
4
+ sicDescription: string | null;
3
5
  companyName: string;
4
- stateOrCountry: string;
6
+ stateOrCountry: string | null;
5
7
  }
@@ -11,6 +11,7 @@ export interface FilingItemXBRL {
11
11
  title: string;
12
12
  link: string;
13
13
  guid: string;
14
+ url: string;
14
15
  enclosureUrl: string;
15
16
  enclosureLength: number;
16
17
  enclosureType: string;
@@ -1,3 +1,4 @@
1
+ export type TransactionCode = 'S' | 'V' | 'A' | 'D' | 'F' | 'I' | 'M' | 'C' | 'E' | 'H' | 'O' | 'X' | 'G' | 'L' | 'W' | 'Z' | 'J' | 'K' | 'U';
1
2
  export interface Owner {
2
3
  ownerName: string;
3
4
  ownerCik: number;
@@ -22,7 +23,29 @@ export interface InsiderTransaction {
22
23
  isDirectOwnership: boolean;
23
24
  securityTitle: string;
24
25
  transactionDate: string;
25
- transactionCode: string;
26
+ /**
27
+ * ### Transaction Codes
28
+ * - S: Sale
29
+ * - V: Voluntary Reporting
30
+ * - A: Grant
31
+ * - D: Sale to Issuer
32
+ * - F: Payment of Exercise Price
33
+ * - I: Discretionary Transaction
34
+ * - M: Conversion of Derivative Exempt
35
+ * - C: Conversion of Derivative
36
+ * - E: Expiration of Short Derivative Position
37
+ * - H: Expiration of Long Derivative Position
38
+ * - O: Exercise of out-of-the-money Derivative
39
+ * - X: Exercise of in-the-money Derivative
40
+ * - G: Gift
41
+ * - L: Small Acquisition
42
+ * - W: Acquisition or Disposition By Will or Laws
43
+ * - Z: Voting Trust Deposit or Withdrawal
44
+ * - J: Other Acquisition or Disposition
45
+ * - K: Equity Swap
46
+ * - U: Disposition Change in Control
47
+ */
48
+ transactionCode: TransactionCode;
26
49
  transactionShares: number;
27
50
  sharesOwnedFollowingTransaction: number;
28
51
  lineNumber: number;
@@ -30,3 +53,26 @@ export interface InsiderTransaction {
30
53
  form: string;
31
54
  accessionNumber: string;
32
55
  }
56
+ export type TransactionType = 'Acquire' | 'Dispose';
57
+ export interface InsiderTransactionExtended {
58
+ filerName: string;
59
+ filerPosition: string;
60
+ filerPositionTypes: string[];
61
+ securityType: string;
62
+ securityTypeUnderlying: string | null;
63
+ category: 'Derivative' | 'Non-Derivative';
64
+ date: string;
65
+ dateExecuted: string | null;
66
+ dateExpiration: string | null;
67
+ dateExercisable: string | null;
68
+ transactionDescription: string | null;
69
+ transactionCode: TransactionCode | null;
70
+ transactionType: TransactionType | null;
71
+ sharesEnding: number | null;
72
+ shares: number | null;
73
+ sharesUnderlying: number | null;
74
+ price: number | null;
75
+ priceExcercised: number | null;
76
+ ownership: string;
77
+ explainationByKey: Partial<Record<keyof InsiderTransactionExtended, string>>;
78
+ }
@@ -1,49 +1,4 @@
1
- interface TransactionDescriptionByCode {
2
- S: 'Sale';
3
- V: 'Voluntary Reporting';
4
- A: 'Grant';
5
- D: 'Sale to Issuer';
6
- F: 'Payment of Exercise Price';
7
- I: 'Discretionary Transaction';
8
- M: 'Conversion of Derivative Exempt';
9
- C: 'Conversion of Derivative';
10
- E: 'Expiration of Short Derivative Position';
11
- H: 'Expiration of Long Derivative Position';
12
- O: 'Exercise of out-of-the-money Derivative';
13
- X: 'Exercise of in-the-money Derivative';
14
- G: 'Gift';
15
- L: 'Small Acquisition';
16
- W: 'Acquisition or Disposition By Will or Laws';
17
- Z: 'Voting Trust Deposit or Withdrawal';
18
- J: 'Other Acquisition or Disposition';
19
- K: 'Equity Swap';
20
- U: 'Disposition Change in Control';
21
- }
22
- export type TransactionType = 'Acquire' | 'Dispose';
23
- export type TransactionCode = keyof TransactionDescriptionByCode;
24
- export type TransactionDescription = TransactionDescriptionByCode[TransactionCode];
25
- export interface InsiderTransactionExtended {
26
- filerName: string;
27
- filerPosition: string;
28
- filerPositionTypes: string[];
29
- securityType: string;
30
- securityTypeUnderlying: string | null;
31
- category: 'Derivative' | 'Non-Derivative';
32
- date: string;
33
- dateExecuted: string | null;
34
- dateExpiration: string | null;
35
- dateExercisable: string | null;
36
- transactionDescription: string | null;
37
- transactionCode: TransactionCode | null;
38
- transactionType: TransactionType | null;
39
- sharesEnding: number | null;
40
- shares: number | null;
41
- sharesUnderlying: number | null;
42
- price: number | null;
43
- priceExcercised: number | null;
44
- ownership: string;
45
- explainationByKey: Partial<Record<keyof InsiderTransactionExtended, string>>;
46
- }
1
+ import type { InsiderTransactionExtended } from './insider-transaction.type';
47
2
  export interface InstitutionalHolder {
48
3
  name: string;
49
4
  origin: string;
@@ -94,4 +49,3 @@ export interface FormDef14aData {
94
49
  holders: Holder[];
95
50
  }
96
51
  export type DailyFilingFormType = '10-K' | '10-Q' | '8-K' | '14' | '485' | 'S-8' | 'ALL';
97
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sec-edgar-api",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.",
5
5
  "main": "build/index.js",
6
6
  "author": "Andrew Evers (https://github.com/andyevers)",