sec-edgar-api
Version:
Fetch and parse SEC earnings reports and other filings. Useful for financial analysis.
57 lines (56 loc) • 2.51 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTaxonomyFromId = exports.getLabelByTaxonomy = void 0;
/**
* Gets labels by taxonomy from the label linkbase. priority level: verboseLabel > terseLabel > label.
*/
function getLabelByTaxonomy(labelLinkbase) {
var _a;
var labelByTaxonomy = {};
var taxonomyWithVerboseLabels = new Set();
(_a = labelLinkbase.labelLink) === null || _a === void 0 ? void 0 : _a.forEach(function (link) {
var _a;
(_a = link.label) === null || _a === void 0 ? void 0 : _a.forEach(function (_a) {
var _b = _a.label, label = _b === void 0 ? '' : _b, _c = _a.text, text = _c === void 0 ? '' : _c, _d = _a.role, role = _d === void 0 ? '' : _d;
var taxonomy = getTaxonomyFromId(label);
// skip if verbose label already exists for this taxonomy
if (taxonomyWithVerboseLabels.has(taxonomy)) {
return;
}
// label, terseLabel, or verboseLabel
var labelType = role.substring(role.lastIndexOf('/') + 1);
// skip periodStartLabel. Used for beginning cash position, but overwrites end cash position.
if (labelType === 'periodStartLabel') {
return;
}
if (labelType === 'verboseLabel') {
taxonomyWithVerboseLabels.add(taxonomy);
}
// prefer terseLabel over regular label
if (!labelByTaxonomy[taxonomy] || labelType === 'terseLabel' || labelType === 'verboseLabel') {
labelByTaxonomy[taxonomy] = text;
}
});
});
return labelByTaxonomy;
}
exports.getLabelByTaxonomy = getLabelByTaxonomy;
function isPascaleCase(str) {
var startsWithUpperCase = str && str[0].toLowerCase() !== str[0];
return startsWithUpperCase && str.split('').some(function (c) { return c.toLowerCase() === c; });
}
var knownPrefixes = {
'us-gaap': true,
'ifrs-full': true,
dei: true,
srt: true,
country: true,
};
function getTaxonomyFromId(id) {
var parts = id.split('_');
var isLabelIndicatorPosition3 = parts[2] === 'lbl';
var isKnownPrefixPosition1 = knownPrefixes[parts[0]] === true;
var isNameInPosition2 = parts.length <= 2 || isLabelIndicatorPosition3 || isKnownPrefixPosition1 || isPascaleCase(parts[1]);
return isNameInPosition2 ? parts.slice(0, 2).join(':') : parts.slice(1, 3).join(':');
}
exports.getTaxonomyFromId = getTaxonomyFromId;
;