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 This Package?
This package provides EDIFACT-specific parsers for the UN/EDIFACT EDI standard. It works with @ediflow/core to parse EDIFACT messages (ORDERS, INVOIC, DESADV, etc.).
import { EdifactMessageParser } from '@ediflow/edifact';
import { ParseEDIUseCase } from '@ediflow/core';
// Parse EDIFACT message
const parser = new EdifactMessageParser(/* ... */);
const parseUseCase = new ParseEDIUseCase(parser, definitionLoader);
const message = parseUseCase.execute(edifactData);๐ Migration from @ediflow/core
โ ๏ธ Important: EDIFACT parsers in @ediflow/core are deprecated and will be removed in v1.0.0.
Before (Deprecated):
import { EdifactMessageParser } from '@ediflow/core/infrastructure';After (Recommended):
import { EdifactMessageParser } from '@ediflow/edifact';Installation:
# Old way (still works but deprecated):
npm install @ediflow/core
# New way (recommended):
npm install @ediflow/core @ediflow/edifact๐ฏ 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
} from '@ediflow/edifact';
import { ParseEDIUseCase, RepositoryManager } from '@ediflow/core';
// EDIFACT ORDERS D96A message
const edifactData = `UNB+UNOC:3+SENDER+RECEIVER+240204:1200+1++ORDERS'UNH+1+ORDERS:D:96A:UN'BGM+220+ORDER123+9'DTM+137:20240204:102'UNT+4+1'UNZ+1+1'`;
// Setup parsers
const delimiterDetector = new EdifactDelimiterDetector();
const tokenizer = new EdifactTokenizer();
const segmentParser = new EdifactSegmentParser();
const messageParser = new EdifactMessageParser(
delimiterDetector,
tokenizer,
segmentParser
);
// Setup use case
const repositoryManager = new RepositoryManager();
const definitionLoader = createDefinitionLoader(repositoryManager);
const useCase = new ParseEDIUseCase(messageParser, definitionLoader);
// Parse
const message = useCase.execute(edifactData);
console.log(message.getSegments());
// [UNB, UNH, BGM, DTM, UNT, UNZ]๐๏ธ 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 versions through data packages:
- @ediflow/edifact-d96a - Version D.96A
- @ediflow/edifact-d01b - Version D.01B
- @ediflow/edifact-d12a - Version D.12A
- @ediflow/edifact-d20b - Version D.20B
Common message types: ORDERS, INVOIC, DESADV, ORDRSP, PRICAT, etc.
๐งช Testing
# Run tests
npm test
# Watch mode
npm run test:watch
# Coverage
npm run test:coverage๐ Related Packages
- @ediflow/core - Core domain & application logic (required)
- @ediflow/x12 - X12 parser
- @ediflow/edifact-d96a - EDIFACT D96A definitions
๐ Documentation
๐ค Contributing
See CONTRIBUTING.md
๐ License
MIT - See LICENSE
Part of EdiFlow - Modern, type-safe EDI parsing for TypeScript/JavaScript