Function: decodeSegment()
decodeSegment(
raw,delimiters,emit,position):X12Segment
Decode a raw segment string into an X12Segment. Splits on the
detected element separator (honouring the ?-release-character escape),
preserves the verbatim raw text, and surfaces dangling-release warnings
via the supplied emitter with positional context tied to the segment.
Never throws - malformed input produces a best-effort segment and any
issues surface as Tier-2 warnings via emit. An empty input string
decodes to an empty segment (id: "", elements: [""]); callers that
care can guard.
Parameters
raw
string
delimiters
emit
(w) => void
position
Returns
Example
import { decodeSegment } from "@cosyte/x12";
const d = { element: "*", repetition: "^", component: ":", segment: "~" };
const seg = decodeSegment("NM1*IL*1*DOE*JANE", d, () => {}, { segmentIndex: 5 });
seg.id; // "NM1"
seg.elements[3]; // "DOE"