e-rechnung-parser
v0.1.0
Published
Parse German e-invoices (XRechnung UBL/CII, ZUGFeRD/Factur-X). Extract structured data from XML and PDF. Browser + Node.js compatible.
Maintainers
Readme
e-rechnung-parser
Parse German e-invoices (XRechnung UBL/CII, ZUGFeRD/Factur-X). Extracts structured invoice data from XML. Works in Node.js and browsers.
Supported Formats
| Format | Standard | Notes | |--------|----------|-------| | XRechnung UBL 2.1 | EN 16931 | Universal Business Language | | XRechnung CII | EN 16931 | Cross Industry Invoice | | ZUGFeRD 2.x | EN 16931 | German e-invoice standard | | Factur-X | EN 16931 | French/European variant of ZUGFeRD |
Installation
npm install e-rechnung-parserUsage
import { parse } from 'e-rechnung-parser';
const xml = `<?xml version="1.0"?>...`; // XRechnung or ZUGFeRD XML
const invoice = parse(xml);
console.log(invoice.invoiceNumber); // e.g. "RE-2024-0042"
console.log(invoice.issueDate); // e.g. "2024-03-15"
console.log(invoice.seller.name); // e.g. "Musterfirma GmbH"
console.log(invoice.buyer.name); // e.g. "Kunde AG"
console.log(invoice.totalAmount); // e.g. 595.00
console.log(invoice.currency); // e.g. "EUR"
console.log(invoice.lineItems); // Array of line itemsAuto-detect format
parse() auto-detects XRechnung UBL, XRechnung CII, and ZUGFeRD/Factur-X.
Parse specific format
import { parseUBL, parseCII } from 'e-rechnung-parser/parser';
const invoice = parseUBL(xml); // Force UBL
const invoice = parseCII(xml); // Force CIIOutput Schema
interface Invoice {
format: 'ubl' | 'cii' | 'zugferd';
invoiceNumber: string;
issueDate: string; // ISO 8601 (YYYY-MM-DD)
dueDate?: string;
currency: string; // ISO 4217 (e.g. "EUR")
seller: Party;
buyer: Party;
lineItems: LineItem[];
subtotal: number; // Net amount
taxAmount: number;
totalAmount: number; // Gross amount
taxBreakdown: TaxBreakdown[];
notes?: string[];
buyerReference?: string; // Leitweg-ID
orderReference?: string;
}
interface Party {
name: string;
address?: Address;
taxId?: string; // USt-IdNr
vatId?: string;
contact?: Contact;
iban?: string;
bic?: string;
}
interface LineItem {
id: string;
name: string;
description?: string;
quantity: number;
unit: string;
unitPrice: number;
netAmount: number;
taxRate: number;
taxCategory?: string;
}Live Demo
Try it at e-rechnung.detmers-publish.de — drag and drop any XRechnung or ZUGFeRD file.
License
MIT — see LICENSE
