Skip to content

@ediocracy/parser / functions

function

readX12() ​

readX12(text): X12Document

Defined in: packages/parser/src/reader/reader.ts:426

Reads X12 text into its interchanges, functional groups and transaction sets.

Problems that leave the structure readable, such as a control number that does not match, are returned as findings. Whitespace, Ctrl-Z and NUL around interchanges, and a byte order mark at the start, are skipped.

Parameters ​

ParameterTypeDescription
textstringThe whole X12 text, for example a clearinghouse response body.

Returns ​

X12Document

The interchanges in the order they appear, and the reader's findings.

Throws ​

When the text cannot be read, for example when it has no ISA or an envelope has no trailer.

Example ​

ts
import { readX12 } from '@ediocracy/parser';

const document = readX12(text);
for (const interchange of document.interchanges) {
    console.log(interchange.header.element(13), interchange.groups.length);
}