Skip to main content
Version: v0.0.2

Function: detectDelimiters()

detectDelimiters(raw): Delimiters

Detect the four X12 delimiters from a raw input string by reading fixed byte positions inside the ISA envelope. Validates that:

  • the input is at least ISA_MIN_LENGTH bytes (else X12_ISA_TOO_SHORT),
  • the input begins with the literal "ISA" (else X12_NO_ISA_HEADER),
  • each delimiter is a single visible (non-whitespace, non-control) character and the four are mutually distinct (else X12_INVALID_DELIMITERS),
  • the detected element separator actually appears at every fixed ISA element-separator position (else X12_INVALID_DELIMITERS) - guards against an input that begins with "ISA" followed by structurally wrong bytes (e.g. a tab as element separator with : further in).

Phase 1 is liberal in what it accepts AFTER the ISA - downstream envelope walking emits Tier-2 warnings rather than throwing. But the ISA itself MUST be structurally readable; otherwise no later stage has a delimiter set to work with.

Parameters

raw

string

Returns

Delimiters

Example

import { detectDelimiters } from "@cosyte/x12";
const d = detectDelimiters("ISA*00* *00* *ZZ*SENDER *ZZ*RECEIVER *250101*1200*^*00501*000000001*0*P*:~GS*HC*S*R*20250101*1200*1*X*005010X222A2~...");
d.element; // "*"
d.repetition; // "^"
d.component; // ":"
d.segment; // "~"