Skip to main content
Version: v0.0.2

Function: parseX12()

Internal

  • implementation signature; overload signatures above carry the public JSDoc + @example.

Call Signature

parseX12(raw): X12Interchange

Parse a raw X12 healthcare interchange (string or Buffer) into an X12Interchange. The parser is lenient by default: recoverable deviations from 005010 are reported via ix.warnings and (optionally) options.onWarning, never thrown. Four unrecoverable structural errors throw X12ParseError: X12_EMPTY_INPUT, X12_NO_ISA_HEADER, X12_ISA_TOO_SHORT, X12_INVALID_DELIMITERS. Opt into strict mode with { strict: true } to escalate every Tier-2 warning into an X12ParseError carrying the warning's code.

Phase 1 decodes the envelope (ISA / GS / ST / SE / GE / IEA) and detects the four delimiters from fixed ISA byte positions. Transaction- set bodies inside each ST..SE are kept opaque at this phase - tx.segments carries the raw segment strings (terminator stripped). Phase 2 adds segment/element/composite/repetition decode on top.

Parameters

raw

string | Buffer<ArrayBufferLike>

Returns

X12Interchange

Example

import { parseX12, WARNING_CODES } from "@cosyte/x12";

const raw = "ISA*00* *00* *ZZ*SENDER *ZZ*RECEIVER *250101*1200*^*00501*000000001*0*P*:~GS*HC*S*R*20250101*1200*1*X*005010X222A2~ST*837*0001~SE*2*0001~GE*1*1~IEA*1*000000001~";
const ix = parseX12(raw);
ix.delimiters.element; // "*"
ix.delimiters.component; // ":"
ix.delimiters.segment; // "~"
ix.groups[0]?.gs.elements[1]; // "HC"
for (const w of ix.warnings) {
if (w.code === WARNING_CODES.X12_PRE_005010) {
// sender on pre-005010 version family
}
}

Call Signature

parseX12(raw, options): X12Interchange

Parse a raw X12 healthcare interchange (string or Buffer) into an X12Interchange. The parser is lenient by default: recoverable deviations from 005010 are reported via ix.warnings and (optionally) options.onWarning, never thrown. Four unrecoverable structural errors throw X12ParseError: X12_EMPTY_INPUT, X12_NO_ISA_HEADER, X12_ISA_TOO_SHORT, X12_INVALID_DELIMITERS. Opt into strict mode with { strict: true } to escalate every Tier-2 warning into an X12ParseError carrying the warning's code.

Phase 1 decodes the envelope (ISA / GS / ST / SE / GE / IEA) and detects the four delimiters from fixed ISA byte positions. Transaction- set bodies inside each ST..SE are kept opaque at this phase - tx.segments carries the raw segment strings (terminator stripped). Phase 2 adds segment/element/composite/repetition decode on top.

Parameters

raw

string | Buffer<ArrayBufferLike>

options

X12ParseOptions

Returns

X12Interchange

Example

import { parseX12, WARNING_CODES } from "@cosyte/x12";

const raw = "ISA*00* *00* *ZZ*SENDER *ZZ*RECEIVER *250101*1200*^*00501*000000001*0*P*:~GS*HC*S*R*20250101*1200*1*X*005010X222A2~ST*837*0001~SE*2*0001~GE*1*1~IEA*1*000000001~";
const ix = parseX12(raw);
ix.delimiters.element; // "*"
ix.delimiters.component; // ":"
ix.delimiters.segment; // "~"
ix.groups[0]?.gs.elements[1]; // "HC"
for (const w of ix.warnings) {
if (w.code === WARNING_CODES.X12_PRE_005010) {
// sender on pre-005010 version family
}
}