JSPM

@ediflow/edifact

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q71748F
  • License MIT

EDIFACT EDI Parser - Format-specific infrastructure for UN/EDIFACT standard

Package Exports

  • @ediflow/edifact

Readme

@ediflow/edifact

EDIFACT EDI Parser - Format-specific infrastructure for UN/EDIFACT standard

Part of the EdiFlow ecosystem - Modern, type-safe EDI parsing for TypeScript/JavaScript.


๐Ÿ†• What's in v0.3.0

  • โœ… Full EDIFACT parser โ€” UNB/UNH/UNT/UNZ envelope support
  • โœ… Builder + EnvelopeBuilder โ€” Construct and wrap messages programmatically
  • โœ… Validation โ€” EdifactValidationServiceBuilder with STRICT/LENIENT levels
  • โœ… All data packages โ€” D.96A, D.01B, D.12A, D.20B, EANCOM 2002

This package provides EDIFACT-specific parsers, builders, and validators for the UN/EDIFACT standard.

import {
  EdifactMessageParser,
  EdifactDelimiterDetector,
  EdifactTokenizer,
  EdifactSegmentParser,
} from '@ediflow/edifact';

const parser  = new EdifactMessageParser(
  new EdifactDelimiterDetector(), new EdifactTokenizer(), new EdifactSegmentParser(),
);
const message = parser.parse(edifactString);
console.log(message.messageType.value); // 'ORDERS'

๐ŸŽฏ Why a Separate Package?

Clean Architecture:

  • @ediflow/core = Format-agnostic domain & application logic
  • @ediflow/edifact = EDIFACT-specific parsing infrastructure
  • @ediflow/x12 = X12-specific parsing infrastructure

This allows you to:

  • โœ… Only install parsers you need (tree-shaking)
  • โœ… Keep core small and format-agnostic
  • โœ… Add new formats without bloating core

๐Ÿ“ฅ Installation

npm install @ediflow/core @ediflow/edifact

๐Ÿš€ Quick Start

import {
  EdifactMessageParser,
  EdifactDelimiterDetector,
  EdifactTokenizer,
  EdifactSegmentParser,
  EdifactValidationServiceBuilder,
} from '@ediflow/edifact';

const edifact = `UNB+UNOC:3+SENDER:14+RECEIVER:14+260503:0800+1'` +
                `UNH+1+ORDERS:D:96A:UN'` +
                `BGM+220+PO-001+9'` +
                `DTM+137:20260503:102'` +
                `UNT+4+1'` +
                `UNZ+1+1'`;

// 1. Parse
const parser = new EdifactMessageParser(
  new EdifactDelimiterDetector(),
  new EdifactTokenizer(),
  new EdifactSegmentParser(),
);
const message = parser.parse(edifact);

console.log(message.standard);           // 'EDIFACT'
console.log(message.version.value);      // 'D.96A'
console.log(message.messageType.value);  // 'ORDERS'
console.log(message.segments.length);    // 4 (BGM, DTM + envelope stripped)

// 2. Validate
const validator = EdifactValidationServiceBuilder.forEDIFACT();
const result    = validator.validate(message);
console.log(result.isValid);             // true

๐Ÿ—๏ธ Architecture

@ediflow/edifact/
โ””โ”€โ”€ infrastructure/
    โ””โ”€โ”€ parsers/
        โ”œโ”€โ”€ EdifactTokenizer.ts           # Splits EDIFACT into tokens
        โ”œโ”€โ”€ EdifactSegmentParser.ts       # Parses segments
        โ”œโ”€โ”€ EdifactDelimiterDetector.ts   # Detects delimiters from UNA
        โ””โ”€โ”€ EdifactMessageParser.ts       # Full message parsing

๐ŸŽ“ EDIFACT Delimiters

Delimiter Default Purpose Example
Component : Separates composite elements UNOC:3
Data Element + Separates data elements UNB+UNOC:3+...
Decimal . Decimal point 123.45
Escape ? Escapes special characters TEST?+DATA
Segment ' Terminates segments UNH+1+ORDERS:D:96A:UN'

UNA Segment (optional): UNA:+.? ' - Defines custom delimiters

๐Ÿ“š Supported Message Types

Works with all EDIFACT data packages (all MIT licensed):

Package Messages Description
@ediflow/edifact-d96a 126 D.96A (1996)
@ediflow/edifact-d01b 211 D.01B (2001) โ€” largest message count
@ediflow/edifact-d12a 196 D.12A (2012)
@ediflow/edifact-d20b 195 D.20B (2020) โ€” latest
@ediflow/eancom-2002 49 EANCOM 2002 โ€” GS1 retail

Total: 777 unique message types across all EDIFACT versions.

Message Type Categories (D.12A โ€” 196 types)

๐Ÿ“ฆ Supply Chain & Logistics DESADV, ORDERS, ORDRSP, ORDCHG, DELFOR, DELJIT, RECADV, COPARN, COREOR, COPRAR, COPINO, IFTMIN, IFTMAN, IFTMBC, IFTMCS, IFTSTA, IFTSAI, IFCSUM, COSTCO, COSTOR

๐Ÿ’ฐ Finance & Payment INVOIC, REMADV, PAYORD, PAYEXT, PAYMUL, PAYDUC, FINSTA, FINPAY, CREADV, CREEXT, CREMUL, DEBADV, DEBMUL, DEBREC, DIRDEB

๐Ÿ“‹ Catalog & Inventory PRICAT, PRIHIS, INVRPT, SLSRPT, SLSFCT, QUOTES, REQOTE

๐Ÿšข Transport & Customs CUSCAR, CUSDEC, CUSEXP, CUSRES, BAPLIE, COARRI, CODECO, VESDEP, MOVINS, BERMAN, HANMOV, IFTSTQ, IFTDGN, SAFHAZ, PAXLST

๐Ÿฅ Healthcare MEQPOS, MEDPID, MEDPRE, MEDREQ, MEDRPT, MEDRUC, INSDES, INSREQ, INSPRE, INSRPT

๐Ÿฆ Banking & Trade Finance BANSTA, DOCADV, DOCAPP, DOCARE, DOCAMA, DOCAMI, DOCAMR, DOCINF, BOPBNK, BOPCUS, BOPDIR, BOPINF

๐Ÿ“Š Reporting & Statistics STATAC, STLRPT, TPFREP, INVRPT, RDRMES, ITRRPT, GENRAL, GESMES

Plus: PARTIN, AUTHOR, APERAK, CONTRL, KEYMAN, and 100+ more

๐Ÿงช Testing

# Run tests
npm test

# Watch mode
npm run test:watch

# Coverage
npm run test:coverage

๐Ÿ“– Documentation

๐Ÿค Contributing

See CONTRIBUTING.md

๐Ÿ“„ License

MIT - See LICENSE


Part of EdiFlow - Modern, type-safe EDI parsing for TypeScript/JavaScript