sec-edgar-api 0.5.11 → 1.0.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.
@@ -1,4 +1,4 @@
1
- import type { InsiderTransaction, Issuer, Owner, XMLParams } from '../../../types';
1
+ import { Owner, InsiderTransaction, Issuer, XMLParams } from '../../../types';
2
2
  export declare function parseInsiderTransactions(params: XMLParams): {
3
3
  transactions: InsiderTransaction[];
4
4
  owners: Owner[];
@@ -1,50 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseInsiderTransactions = void 0;
4
- var HtmlTableExtractor_1 = require("../../HtmlTableExtractor");
4
+ function parseTable(html) {
5
+ var rows = html.split('<tr');
6
+ return rows
7
+ .map(function (rowHtml) {
8
+ return rowHtml
9
+ .split('<td')
10
+ .map(function (cellHtml) { return cellHtml.substring(cellHtml.indexOf('>') + 1, cellHtml.lastIndexOf('</td>')); })
11
+ .slice(1);
12
+ })
13
+ .filter(function (row) { return row.length > 0; });
14
+ }
15
+ function stripHtml(html) {
16
+ return html
17
+ .replace(/<.*?>/g, '')
18
+ .replace(/&nbsp;/g, ' ')
19
+ .replace(/\n/g, ' ')
20
+ .replace(/\s+/, ' ')
21
+ .trim();
22
+ }
23
+ function toNumber(value) {
24
+ return Number(value.replace(/,/g, '').trim()) || 0;
25
+ }
5
26
  function parseInsiderTransactions(params) {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
27
+ var _a, _b, _c, _d;
7
28
  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 getTableHeadHtml = function (table) {
22
- var _a;
23
- var match = table.html.replace(/\n/g, '').match(/<b>.*?<\/b>/g);
24
- var matches = Array.isArray(match) ? match : [];
25
- return (_a = matches.find(function (match) { return match.includes('<a'); })) !== null && _a !== void 0 ? _a : null;
26
- };
27
- var tableCompany = tables.find(function (table) { return table.html.includes('cgi-bin/browse-edgar?action=getcompany') && getTableHeadHtml(table) !== null; });
28
- var tableCompanyHead = tableCompany ? getTableHeadHtml(tableCompany) || '' : '';
29
- var issuerCik = Number((_b = (_a = tableCompanyHead.split('</a>')[0]) === null || _a === void 0 ? void 0 : _a.split('>').pop()) === null || _b === void 0 ? void 0 : _b.trim()) || 0;
30
- var issuerName = ((_d = (_c = tableCompanyHead.split('(')[0]) === null || _c === void 0 ? void 0 : _c.split('>').pop()) === null || _d === void 0 ? void 0 : _d.trim()) || '';
31
- var cells = (_e = tableCompany === null || tableCompany === void 0 ? void 0 : tableCompany.rows.flat()) !== null && _e !== void 0 ? _e : [];
32
- cells.find(function (cell) { return cell.html.toLowerCase().includes('<b'); });
33
- var getHeaderRow = function (table) { return table.rows.find(function (row) { return row.some(function (cell) { return cell.isHeaderRowCell; }); }); };
34
- var findTableWithCol = function (colTextLower) {
35
- return tables.find(function (table) { var _a; return (_a = getHeaderRow(table)) === null || _a === void 0 ? void 0 : _a.some(function (cell) { return String(cell.valueParsed).toLowerCase().includes(colTextLower); }); });
36
- };
37
- var tableOwners = findTableWithCol('type of owner');
38
- var tableTransactions = findTableWithCol('security name');
39
- var stripHtml = function (html) {
40
- return html
41
- .replace(/<.*?>/g, '')
42
- .replace(/&nbsp;/g, ' ')
43
- .replace(/\n/g, ' ')
44
- .replace(/\s+/, ' ')
45
- .trim();
46
- };
47
- var ownerByCik = new Map();
29
+ var ownerTableHeadingIndex = xml.indexOf('sortid=');
30
+ var transactionTableIdIndex = xml.indexOf('id="transaction-report"');
31
+ if (ownerTableHeadingIndex === -1) {
32
+ throw new Error('Owner table heading not found in XML data');
33
+ }
34
+ var ownerTableStartIndex = xml.lastIndexOf('<table', ownerTableHeadingIndex);
35
+ var ownerTableEndIndex = xml.indexOf('</table>', ownerTableHeadingIndex) + 8;
36
+ var ownerTableHtml = xml.substring(ownerTableStartIndex, ownerTableEndIndex);
37
+ var transactionTableStartIndex = xml.lastIndexOf('<table', transactionTableIdIndex);
38
+ var transactionTableEndIndex = xml.indexOf('</table>', transactionTableIdIndex) + 8;
39
+ var transactionTableHtml = xml.substring(transactionTableStartIndex, transactionTableEndIndex);
40
+ var issuerUrlIndex = xml.indexOf('cgi-bin/browse-edgar?action=getcompany');
41
+ var issuerUrlStartIndex = xml.lastIndexOf('<b>', issuerUrlIndex) + 3;
42
+ var issuerUrlEndIndex = xml.indexOf('</b>', issuerUrlIndex);
43
+ var issuerHtml = xml.substring(issuerUrlStartIndex, issuerUrlEndIndex).trim();
44
+ var issuerHtmlCikStart = issuerHtml.lastIndexOf('(') + 1;
45
+ var issuerCik = toNumber(stripHtml(issuerHtml.substring(issuerHtmlCikStart, issuerHtml.lastIndexOf(')'))));
46
+ var issuerName = issuerHtml.substring(0, issuerHtmlCikStart - 1).trim();
48
47
  var headerOwner = ['owner_name', 'filings', 'transaction_date', 'type_of_owner'];
49
48
  var headerTransaction = [
50
49
  'acquisition_or_disposition',
@@ -60,33 +59,37 @@ function parseInsiderTransactions(params) {
60
59
  'owner_cik',
61
60
  'security_title',
62
61
  ];
63
- for (var _i = 0, _r = (_f = tableOwners === null || tableOwners === void 0 ? void 0 : tableOwners.rows) !== null && _f !== void 0 ? _f : []; _i < _r.length; _i++) {
64
- var row = _r[_i];
65
- if ((_g = row[0]) === null || _g === void 0 ? void 0 : _g.isHeaderRowCell)
66
- continue;
62
+ var ownerByCik = new Map();
63
+ var ownerRows = parseTable(ownerTableHtml);
64
+ var transactionRows = parseTable(transactionTableHtml);
65
+ var isSwitchedOwnerIssuer = stripHtml((_b = (_a = ownerRows[0]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toLowerCase()).includes('issuer') || false;
66
+ for (var i = 1; i < ownerRows.length; i++) {
67
+ var row = ownerRows[i];
68
+ // if (row.length === 0 || row[0].includes('Owner Name') || row[0].includes('Issuer')) continue // Skip header row
67
69
  var owner = {
68
70
  ownerName: '',
69
71
  ownerCik: 0,
70
72
  ownerPosition: null,
71
73
  isDirector: false,
72
74
  isOfficer: false,
75
+ isTenPercentOwner: false,
73
76
  };
74
- for (var _s = 0, row_1 = row; _s < row_1.length; _s++) {
75
- var cell = row_1[_s];
76
- var colName = headerOwner[cell.colIndex];
77
- var htmlStripped = stripHtml(cell.html);
77
+ for (var i_1 = 0; i_1 < row.length; i_1++) {
78
+ var colName = headerOwner[i_1];
79
+ var htmlStripped = stripHtml(row[i_1]);
78
80
  switch (colName) {
79
81
  case 'owner_name':
80
82
  owner.ownerName = htmlStripped.split('Current Name')[0];
81
83
  break;
82
84
  case 'filings':
83
- owner.ownerCik = Number(cell.valueParsed || 0) || 0;
85
+ owner.ownerCik = toNumber(htmlStripped);
84
86
  break;
85
87
  case 'type_of_owner': {
86
- var parts = htmlStripped.split(':');
87
- owner.isDirector = (_h = parts[0]) === null || _h === void 0 ? void 0 : _h.toLowerCase().includes('director');
88
- owner.isOfficer = (_j = parts[0]) === null || _j === void 0 ? void 0 : _j.toLowerCase().includes('officer');
89
- owner.ownerPosition = ((_k = parts[1]) === null || _k === void 0 ? void 0 : _k.trim()) || null;
88
+ var _e = htmlStripped.split(':').map(function (s) { return s.toLowerCase().trim(); }), ownerType = _e[0], _f = _e[1], position = _f === void 0 ? null : _f;
89
+ owner.isDirector = ownerType.includes('director');
90
+ owner.isOfficer = ownerType.includes('officer');
91
+ owner.isTenPercentOwner = ownerType.includes('10 percent') || ownerType.includes('10%');
92
+ owner.ownerPosition = position;
90
93
  break;
91
94
  }
92
95
  }
@@ -94,10 +97,10 @@ function parseInsiderTransactions(params) {
94
97
  ownerByCik.set(owner.ownerCik, owner);
95
98
  }
96
99
  var transactions = [];
97
- for (var _t = 0, _u = (_l = tableTransactions === null || tableTransactions === void 0 ? void 0 : tableTransactions.rows) !== null && _l !== void 0 ? _l : []; _t < _u.length; _t++) {
98
- var row = _u[_t];
99
- if ((_m = row[0]) === null || _m === void 0 ? void 0 : _m.isHeaderRowCell)
100
- continue;
100
+ for (var _i = 0, transactionRows_1 = transactionRows; _i < transactionRows_1.length; _i++) {
101
+ var row = transactionRows_1[_i];
102
+ if (row.length === 0 || row[0].includes('Acquisition or Dis'))
103
+ continue; // Skip header row
101
104
  var transaction = {
102
105
  ownerName: '',
103
106
  ownerCik: 0,
@@ -106,6 +109,9 @@ function parseInsiderTransactions(params) {
106
109
  issuerName: issuerName,
107
110
  isDirector: false,
108
111
  isOfficer: false,
112
+ accessionNumber: '',
113
+ deemedExecutionDate: '',
114
+ form: '',
109
115
  /** true = buy, false = sell */
110
116
  isAcquisition: false,
111
117
  isDirectOwnership: false,
@@ -115,17 +121,15 @@ function parseInsiderTransactions(params) {
115
121
  transactionShares: 0,
116
122
  sharesOwnedFollowingTransaction: 0,
117
123
  lineNumber: 0,
118
- deemedExecutionDate: '',
119
- form: '',
120
- accessionNumber: '',
124
+ isTenPercentOwner: false,
121
125
  };
122
- for (var _v = 0, row_2 = row; _v < row_2.length; _v++) {
123
- var cell = row_2[_v];
124
- var colName = headerTransaction[cell.colIndex];
125
- var htmlStripped = stripHtml(cell.html);
126
+ for (var i = 0; i < row.length; i++) {
127
+ var colName = headerTransaction[i];
128
+ var html = row[i];
129
+ var htmlStripped = stripHtml(html);
126
130
  switch (colName) {
127
131
  case 'acquisition_or_disposition':
128
- transaction.isAcquisition = String(cell.valueParsed).toLowerCase() === 'a';
132
+ transaction.isAcquisition = String(htmlStripped).toLowerCase() === 'a';
129
133
  break;
130
134
  case 'transaction_date':
131
135
  transaction.transactionDate = htmlStripped;
@@ -136,7 +140,7 @@ function parseInsiderTransactions(params) {
136
140
  case 'reporting_owner':
137
141
  break;
138
142
  case 'form': {
139
- var url = (_p = (_o = cell.html.match(/href="([^"]+)"/)) === null || _o === void 0 ? void 0 : _o[1]) !== null && _p !== void 0 ? _p : '';
143
+ var url = (_d = (_c = html.match(/href="([^"]+)"/)) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : '';
140
144
  transaction.accessionNumber = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('-'));
141
145
  transaction.form = htmlStripped;
142
146
  break;
@@ -148,22 +152,23 @@ function parseInsiderTransactions(params) {
148
152
  transaction.isDirectOwnership = htmlStripped.toLowerCase().includes('d');
149
153
  break;
150
154
  case 'num_securities_transacted':
151
- transaction.transactionShares = Number(cell.valueParsed) || 0;
155
+ transaction.transactionShares = toNumber(htmlStripped) || 0;
152
156
  break;
153
157
  case 'num_securities_following':
154
- transaction.sharesOwnedFollowingTransaction = Number(cell.valueParsed) || 0;
158
+ transaction.sharesOwnedFollowingTransaction = toNumber(htmlStripped);
155
159
  break;
156
160
  case 'line_number':
157
- transaction.lineNumber = Number(cell.valueParsed) || 0;
161
+ transaction.lineNumber = toNumber(htmlStripped);
158
162
  break;
159
163
  case 'owner_cik': {
160
- var owner = ownerByCik.get(Number(cell.valueParsed) || 0);
164
+ var owner = ownerByCik.get(toNumber(htmlStripped) || 0);
161
165
  if (owner) {
162
166
  transaction.ownerName = owner.ownerName;
163
167
  transaction.ownerCik = owner.ownerCik;
164
168
  transaction.ownerPosition = owner.ownerPosition;
165
169
  transaction.isDirector = owner.isDirector;
166
170
  transaction.isOfficer = owner.isOfficer;
171
+ transaction.isTenPercentOwner = owner.isTenPercentOwner;
167
172
  }
168
173
  break;
169
174
  }
@@ -174,9 +179,6 @@ function parseInsiderTransactions(params) {
174
179
  }
175
180
  transactions.push(transaction);
176
181
  }
177
- var isSwitchedOwnerIssuer = (_q = tableTransactions === null || tableTransactions === void 0 ? void 0 : tableTransactions.rows) === null || _q === void 0 ? void 0 : _q.some(function (r) {
178
- return r.some(function (c) { return String(c.valueParsed).toLowerCase() === 'issuer'; });
179
- });
180
182
  var owners = Array.from(ownerByCik.values());
181
183
  var issuers = [{ issuerName: issuerName, issuerCik: issuerCik }];
182
184
  // if searching by person, owner and issuer data will be switched
@@ -194,6 +196,10 @@ function parseInsiderTransactions(params) {
194
196
  transaction.ownerName = issuerName;
195
197
  });
196
198
  }
197
- return { transactions: transactions, owners: owners, issuers: issuers };
199
+ return {
200
+ transactions: transactions,
201
+ owners: Array.from(ownerByCik.values()),
202
+ issuers: issuers,
203
+ };
198
204
  }
199
205
  exports.parseInsiderTransactions = parseInsiderTransactions;
@@ -36,8 +36,8 @@ function isWithinDays(params) {
36
36
  return daysDiff < days;
37
37
  }
38
38
  function buildReportsFromFacts(params) {
39
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
40
- var filing = params.filing, facts = params.facts, fiscalPeriod = params.fiscalPeriod, fiscalYear = params.fiscalYear, pathSeparator = params.pathSeparator, cikProp = params.cik;
39
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
40
+ var filing = params.filing, facts = params.facts, fiscalPeriod = params.fiscalPeriod, fiscalYear = params.fiscalYear, pathSeparator = params.pathSeparator, cikProp = params.cik, fiscalYearEnd = params.fiscalYearEnd;
41
41
  var urlParts = (_a = filing === null || filing === void 0 ? void 0 : filing.url.split('/')) !== null && _a !== void 0 ? _a : [];
42
42
  var cik = cikProp !== null && cikProp !== void 0 ? cikProp : urlParts[(_b = urlParts.indexOf('data')) !== null && _b !== void 0 ? _b : -1];
43
43
  var reportFactValues = {
@@ -63,37 +63,36 @@ function buildReportsFromFacts(params) {
63
63
  var roundPlacesByName = new Map();
64
64
  var scaleByName = new Map();
65
65
  var isFocusFactByDateKey = new Map();
66
- var dateYearEnd = new Date(reportFocus.dateReport);
67
- var offsetByFiscalPeriod = { Q1: 9, Q2: 6, Q3: 3, Q4: 0, FY: 0 };
68
- dateYearEnd.setMonth(dateYearEnd.getMonth() + ((_h = offsetByFiscalPeriod[reportFocus.fiscalPeriod]) !== null && _h !== void 0 ? _h : 0));
66
+ var fiscalYearEndMonth = Number(fiscalYearEnd.substring(0, 2));
67
+ var fiscalYearEndDay = Number(fiscalYearEnd.substring(2));
69
68
  var fiscalCalculator = new FactFiscalCalculator_1.default({
70
69
  filings: filing ? [filing] : undefined,
71
70
  facts: facts,
72
- fiscalYearEnd: { day: dateYearEnd.getDate(), month: dateYearEnd.getMonth() + 1 },
71
+ fiscalYearEnd: { day: fiscalYearEndDay, month: fiscalYearEndMonth },
73
72
  });
74
73
  var fiscalsByDateKey = new Map();
75
74
  for (var _i = 0, facts_1 = facts; _i < facts_1.length; _i++) {
76
75
  var fact = facts_1[_i];
77
76
  var dateKey = fact.start ? "".concat(fact.start, "_").concat(fact.end) : fact.end;
78
77
  if (!fiscalsByDateKey.has(dateKey)) {
79
- var _x = fiscalCalculator.getFiscalYearQuarter({ dateStr: fact.end }), quarter = _x.quarter, year = _x.year;
78
+ var _w = fiscalCalculator.getFiscalYearQuarter({ dateStr: fact.end }), quarter = _w.quarter, year = _w.year;
80
79
  var period = FactPeriodResolver_1.default.getPeriod({ end: fact.end, start: fact.start });
81
80
  var fiscalPeriod_1 = (period === 12 && quarter === 4 ? 'FY' : "Q".concat(quarter));
82
81
  fiscalsByDateKey.set(dateKey, { fiscalYear: year, fiscalPeriod: fiscalPeriod_1 });
83
82
  }
84
83
  var isSplitFact = fact === splitFact;
85
- var isFocusFact = (_j = isFocusFactByDateKey.get(dateKey)) !== null && _j !== void 0 ? _j : (isWithinDays({ dateA: fact.end, dateB: reportFocus.dateReport, days: 45 }) || isSplitFact);
86
- (_k = reportByDateRange[dateKey]) !== null && _k !== void 0 ? _k : (reportByDateRange[dateKey] = {
84
+ var isFocusFact = (_h = isFocusFactByDateKey.get(dateKey)) !== null && _h !== void 0 ? _h : (isWithinDays({ dateA: fact.end, dateB: reportFocus.dateReport, days: 45 }) || isSplitFact);
85
+ (_j = reportByDateRange[dateKey]) !== null && _j !== void 0 ? _j : (reportByDateRange[dateKey] = {
87
86
  cik: reportFocus.cik,
88
87
  url: '',
89
- splitDate: (_l = splitFact === null || splitFact === void 0 ? void 0 : splitFact.end) !== null && _l !== void 0 ? _l : null,
88
+ splitDate: (_k = splitFact === null || splitFact === void 0 ? void 0 : splitFact.end) !== null && _k !== void 0 ? _k : null,
90
89
  splitRatio: (splitFact === null || splitFact === void 0 ? void 0 : splitFact.value) ? Number(splitFact.value) : null,
91
90
  dateFiled: reportFocus.dateFiled,
92
91
  dateReport: fact.end,
93
- fiscalPeriod: (_m = fiscalsByDateKey.get(dateKey)) === null || _m === void 0 ? void 0 : _m.fiscalPeriod,
94
- startDate: (_o = fact.start) !== null && _o !== void 0 ? _o : '',
92
+ fiscalPeriod: (_l = fiscalsByDateKey.get(dateKey)) === null || _l === void 0 ? void 0 : _l.fiscalPeriod,
93
+ startDate: (_m = fact.start) !== null && _m !== void 0 ? _m : '',
95
94
  endDate: fact.end,
96
- fiscalYear: (_p = fiscalsByDateKey.get(dateKey)) === null || _p === void 0 ? void 0 : _p.fiscalYear,
95
+ fiscalYear: (_o = fiscalsByDateKey.get(dateKey)) === null || _o === void 0 ? void 0 : _o.fiscalYear,
97
96
  period: FactPeriodResolver_1.default.getPeriod({ start: fact.start, end: fact.end }),
98
97
  isCurrentPeriod: isFocusFact,
99
98
  });
@@ -104,11 +103,11 @@ function buildReportsFromFacts(params) {
104
103
  isFocusFactByDateKey.set(dateKey, isFocusFact);
105
104
  }
106
105
  var el = fact;
107
- var scale = Number((_q = el.scale) !== null && _q !== void 0 ? _q : 0) || 0;
108
- var decimals = Number((_r = el.decimals) !== null && _r !== void 0 ? _r : 0) || 0;
106
+ var scale = Number((_p = el.scale) !== null && _p !== void 0 ? _p : 0) || 0;
107
+ var decimals = Number((_q = el.decimals) !== null && _q !== void 0 ? _q : 0) || 0;
109
108
  var suffix = fact.name.includes(pathSeparator)
110
109
  ? null
111
- : (_s = fact === null || fact === void 0 ? void 0 : fact.segments) === null || _s === void 0 ? void 0 : _s.map(function (_a) {
110
+ : (_r = fact === null || fact === void 0 ? void 0 : fact.segments) === null || _r === void 0 ? void 0 : _r.map(function (_a) {
112
111
  var dimension = _a.dimension, value = _a.value;
113
112
  return "".concat(dimension).concat(pathSeparator).concat(value);
114
113
  }).join(pathSeparator);
@@ -122,8 +121,8 @@ function buildReportsFromFacts(params) {
122
121
  var prevRounding = roundPlacesByName.get(prevFactKey);
123
122
  var prevScale = scaleByName.get(prevFactKey);
124
123
  var prevFact_1 = factByName.get(prevFactKey);
125
- var prevUnit = (_u = (_t = prevFact_1 === null || prevFact_1 === void 0 ? void 0 : prevFact_1.unit) === null || _t === void 0 ? void 0 : _t.split('_').pop()) === null || _u === void 0 ? void 0 : _u.toLowerCase();
126
- var unit = (_w = (_v = fact.unit) === null || _v === void 0 ? void 0 : _v.split('_').pop()) === null || _w === void 0 ? void 0 : _w.toLowerCase();
124
+ var prevUnit = (_t = (_s = prevFact_1 === null || prevFact_1 === void 0 ? void 0 : prevFact_1.unit) === null || _s === void 0 ? void 0 : _s.split('_').pop()) === null || _t === void 0 ? void 0 : _t.toLowerCase();
125
+ var unit = (_v = (_u = fact.unit) === null || _u === void 0 ? void 0 : _u.split('_').pop()) === null || _v === void 0 ? void 0 : _v.toLowerCase();
127
126
  var shouldSkip = [
128
127
  (prevUnit === null || prevUnit === void 0 ? void 0 : prevUnit.length) === 3 && (unit === null || unit === void 0 ? void 0 : unit.length) === 3 && prevUnit !== unit && prevUnit === 'usd',
129
128
  (prevRounding !== null && prevRounding !== void 0 ? prevRounding : 0) < roundPlaces,
@@ -150,11 +149,11 @@ function buildReportsFromFacts(params) {
150
149
  return { reportFocus: reportFocus, reportByDateRange: reportByDateRange, factsFiltered: Array.from(factByName.values()) };
151
150
  }
152
151
  function parseXbrl(params) {
153
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
152
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
154
153
  var parser = new XBRLParser_1.default();
155
- var xml = params.xml, _p = params.includeReport, includeReport = _p === void 0 ? true : _p, options = __rest(params, ["xml", "includeReport"]);
154
+ var xml = params.xml, _o = params.includeReport, includeReport = _o === void 0 ? true : _o, options = __rest(params, ["xml", "includeReport"]);
156
155
  var response = parser.parse(xml, options);
157
- var _q = (_b = (_a = response.instance) === null || _a === void 0 ? void 0 : _a.xbrl) !== null && _b !== void 0 ? _b : {}, _r = _q.contexts, contexts = _r === void 0 ? [] : _r, _s = _q.factElements, factElements = _s === void 0 ? [] : _s;
156
+ var _p = (_b = (_a = response.instance) === null || _a === void 0 ? void 0 : _a.xbrl) !== null && _b !== void 0 ? _b : {}, _q = _p.contexts, contexts = _q === void 0 ? [] : _q, _r = _p.factElements, factElements = _r === void 0 ? [] : _r;
158
157
  var contextById = new Map();
159
158
  contexts.forEach(function (context) { return contextById.set(context.id, context); });
160
159
  var cik = response.header.cik;
@@ -201,17 +200,18 @@ function parseXbrl(params) {
201
200
  if (!reportDate) {
202
201
  throw new Error("Report date not found. Unable to determine fiscal year and period. accn: ".concat(accessionNumber));
203
202
  }
204
- var _t = fiscalCalculator.getFiscalYearQuarter({ dateStr: reportDate !== null && reportDate !== void 0 ? reportDate : '' }), quarter = _t.quarter, year = _t.year;
203
+ var _s = fiscalCalculator.getFiscalYearQuarter({ dateStr: reportDate !== null && reportDate !== void 0 ? reportDate : '' }), quarter = _s.quarter, year = _s.year;
205
204
  fiscalYear = year;
206
205
  fiscalPeriod = (quarter === 4 ? 'FY' : "Q".concat(quarter));
207
206
  }
208
207
  var factsForBuilder = includeReport ? facts : [];
209
- var _u = buildReportsFromFacts({
208
+ var _t = buildReportsFromFacts({
210
209
  facts: factsForBuilder,
211
210
  pathSeparator: '>',
212
211
  fiscalPeriod: (_k = factsForBuilder.find(function (f) { return f.name === 'dei:DocumentFiscalPeriodFocus'; })) === null || _k === void 0 ? void 0 : _k.value,
213
212
  fiscalYear: Number((_m = (_l = factsForBuilder.find(function (f) { return f.name === 'dei:DocumentFiscalYearFocus'; })) === null || _l === void 0 ? void 0 : _l.value) !== null && _m !== void 0 ? _m : 0),
214
213
  cik: response.header.cik,
214
+ fiscalYearEnd: response.header.fiscalYearEnd,
215
215
  filing: {
216
216
  acceptanceDateTime: response.header.acceptanceDatetime,
217
217
  accessionNumber: accessionNumber,
@@ -230,29 +230,9 @@ function parseXbrl(params) {
230
230
  url: "https://www.sec.gov/Archives/edgar/data/".concat(cik, "/").concat(accessionNumberNoHyphens, "/").concat(accessionNumber, ".txt"),
231
231
  urlPrimaryDocument: '',
232
232
  },
233
- }), factsFiltered = _u.factsFiltered, reportFocus = _u.reportFocus, reportByDateRange = _u.reportByDateRange;
233
+ }), factsFiltered = _t.factsFiltered, reportFocus = _t.reportFocus, reportByDateRange = _t.reportByDateRange;
234
234
  // Some concepts have members, but do not have a sum. add the sum to the report.
235
235
  var periodReports = Object.values(reportByDateRange);
236
- for (var _v = 0, periodReports_1 = periodReports; _v < periodReports_1.length; _v++) {
237
- var report = periodReports_1[_v];
238
- for (var key in report) {
239
- if (!key.includes('>'))
240
- continue;
241
- var parts = key.split('>');
242
- var concept = parts.shift();
243
- var center = parts.slice(0, -1).join('>');
244
- if (!concept || report[concept] !== undefined)
245
- continue;
246
- var sum = 0;
247
- for (var k in report) {
248
- var prefix = "".concat(concept, ">").concat(center, ">");
249
- if (k.startsWith(prefix) && !((_o = k.split(prefix).pop()) === null || _o === void 0 ? void 0 : _o.includes('>'))) {
250
- sum += Number(typeof report[k] === 'number' ? report[k] : 0);
251
- }
252
- }
253
- report[concept] = sum;
254
- }
255
- }
256
236
  return __assign(__assign({}, response), { fiscalYear: fiscalYear, fiscalPeriod: fiscalPeriod, facts: factsFiltered, report: factsFiltered.length > 0 ? reportFocus : null, xml: xml, periodReports: periodReports });
257
237
  }
258
238
  exports.parseXbrl = parseXbrl;
@@ -5,6 +5,7 @@ export interface Owner {
5
5
  ownerPosition: string | null;
6
6
  isDirector: boolean;
7
7
  isOfficer: boolean;
8
+ isTenPercentOwner: boolean;
8
9
  }
9
10
  export interface Issuer {
10
11
  issuerName: string;
@@ -14,6 +15,7 @@ export interface InsiderTransaction {
14
15
  ownerName: string;
15
16
  ownerCik: number;
16
17
  ownerPosition: string | null;
18
+ isTenPercentOwner: boolean;
17
19
  issuerCik: number;
18
20
  issuerName: string;
19
21
  isDirector: boolean;
@@ -25,6 +27,7 @@ export interface InsiderTransaction {
25
27
  transactionDate: string;
26
28
  /**
27
29
  * ### Transaction Codes
30
+ * - P: Purchase
28
31
  * - S: Sale
29
32
  * - V: Voluntary Reporting
30
33
  * - A: Grant
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sec-edgar-api",
3
- "version": "0.5.11",
3
+ "version": "1.0.0",
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)",