npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xbrl-parser

v1.2.4

Published

Module for parsing XBRL files for specific market taxonomies

Downloads

187

Readme

xbrl-parser

pr npm publish

XBRL parser and utility for parsing XBRL files.

The library was created specifically for parsing XBRL annual reports for Danish companies to extract income statement and balance data from the (slightly different) taxonomies used for annual reports and consolidate them in the same JSON-like format.

It has very limited support for US-GAAP taxonomy as well.

Install

npm install --save xbrl-parser

Usage

Given a string containing an XBRL XML file (the full contents, not the filename), it will be parsed into a "raw" XBRL format which can be passed on to other parsers. The only parser supported right now is the Danish annual report parser.

import { parseXbrlFile } from 'xbrl-parser';

// Maybe this was loaded with the fs module or from an http request
const xmlString = '<?xml version="1.0" encoding="UTF-8"?><xbrli:xbrl>...</xbrli:xbrl>';

const xbrl = parseXbrlFile(xmlString);
console.log(xbrl);

Using the Danish annual report parser:

import { CvrParser, parseAnnualReport } from 'xbrl-parser';
const report = parseAnnualReport(xmlString, new CvrParser());
console.log(report);

The CvrParser is named like that since it parses information fetched from the Danish national registry cvr.dk. There is also a USGAAPParser for for parsing XBRL for the US-GAAP taxonomy.

Things to watch out for in the annual reports

The code contains some comments for specific cases that have been discovered along the way. Some of the more interesting ones:

  • Some companies report revenue while others report "gross profit". It is unclear what the difference is.
  • Some companies report EBITDA in their PDF reports, but there is no EBITDA field in the taxonomy. As such, EBITDA is a calculated field in the mapped reports.

XBRL spec notes

Usually, the xbrl instance root element is <xbrli:xbrl>. The standard also mentions this here: https://specifications.xbrl.org/xbrl-essentials.html

However, in the wild, other namespaces (or no namespaces) have been observed (like <xbrl>), which may or may not be valid.

In order to make the output more consistent, there are two options:

  1. Completely ignore the namespace prefix for all XML fields. This is not a good option because other namespaces are lost as well, and it could potentially (although unlikely) lead to name clashes of fields when parsed.
  2. Recursively "fix" non-standard namespaces so they are the same.

This library uses the second choice, such that parsed XBRL documents use xbrli: as namespace prefix for XBRL-specific fields.

Danish annual report specifics

The taxonomies for Danish annual reports is documented here (in Danish).

For this taxonomy, namespace renaming also happens for some annual reports, and this library tries to correct it.

US-GAAP annual report specifics

Taxonomies for US-GAAP are available here.

The taxonomy is currenty mapped from only publicly traded companies which might have different reporting structure than SMEs.

Notes to keep in mind

  • IFRS is not supported
  • The field mapping is incomplete.
  • The mapping is done on a best-effort basis and will most definitely not be correct in all cases.

In other words: Use with caution :D