JSPM

@ediflow/edifact

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q69869F
  • 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 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';
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:

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

๐Ÿ“– Documentation

๐Ÿค Contributing

See CONTRIBUTING.md

๐Ÿ“„ License

MIT - See LICENSE


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