danfe-parser
v1.0.13
Published
Parse DANFE XML (NFC-e, NFe) into a normalized Danfe object
Maintainers
Readme
danfe
Parse DANFE XML (NFC-e, NFe) into a normalized Danfe object.
Logic is based on brasizza/danfe-package (Dart).
Install
npm install danfeUsage
import { Danfe } from 'danfe';
const xml = `<?xml version="1.0"?>
<nfeProc>
<NFe>
<infNFe>...</infNFe>
</NFe>
<protNFe>...</protNFe>
</nfeProc>`;
const danfe = Danfe.parseDanfeFromString(xml);
if (danfe) {
console.log(danfe.tipo); // 'NFCe' | 'NFe'
console.log(danfe.dados.emit?.xNome);
console.log(danfe.dados.det);
// ... use the normalized object
}You can also use the function directly: import { parseDanfeFromString } from 'danfe'.
API
Danfe.parseDanfeFromString(xml: string): DanfeData | null
Parses XML and detects type (nfeProc/NFe = NFC-e or NFe). Returns normalizedDanfeDataornullif invalid or unrecognized. Import the type asimport type { DanfeData } from 'danfe'if needed.
Supported XML roots
- nfeProc → NFC-e or NFe (from authorized NFe process)
- NFe → standalone NFe
License
ISC
