Function: parseAstmRecords()
parseAstmRecords(
raw,options?):AstmMessage
Parse an ASTM/CLSI-LIS02 record stream into an immutable AstmMessage.
The stream is a sequence of records separated by CR (with LF/CRLF
tolerated); the first record must be an H header, which declares the
delimiters. Lenient by default - set strict to reject any tolerated deviation.
Several messages in one stream. A message runs H … L, so a stream may carry
more than one, and each H declares the delimiters for the records that follow it.
A later header that declares a different set is honored from that header onward
and flagged ASTM_RECORD_DELIMITERS_REDECLARED; records already read keep the set
they were read with, so a redeclaration never reinterprets earlier bytes. A header
that merely restates the set in force is a no-op and warns nothing. A later header
that cannot declare a usable set keeps the delimiters already in force and warns
ASTM_RECORD_UNREADABLE_REDECLARATION - a set is never guessed, and no record is
dropped. Per-header sets are on each HeaderRecord.delimiters;
AstmMessage.delimiters is the first header's.
Parameters
raw
string | Uint8Array<ArrayBufferLike>
The de-framed record bytes, as a string or Uint8Array (decoded
latin1 so byte values survive 1:1).
options?
AstmParseOptions = {}
Parse options; lenient unless strict is set.
Returns
The parsed, deeply-frozen message.
Throws
AstmParseError on a Tier-3 fatal (EMPTY_INPUT,
ASTM_RECORD_NO_HEADER, ASTM_RECORD_UNDECLARED_DELIMITERS).
Throws
AstmStrictError when strict is set and a deviation occurs.
Example
import { parseAstmRecords, results } from "@cosyte/astm";
const msg = parseAstmRecords("H|\\^&\rP|1\rO|1|ACC\rR|1|^^^687|28.6|U/L||N||F\rL|1|N\r");
results(msg)[0]?.value; // "28.6"