Function: serializeField()
serializeField(
field,d?):string
Serialize a single AstmField to its spec-clean wire text, re-escaping each component. A low-level helper for callers assembling a field outside a whole record.
Parameters
field
The field to serialize.
d?
Delimiters = CANONICAL_DELIMITERS
The delimiters to emit against; defaults to H|\^&.
Returns
string
The escaped field text.
Throws
AstmSerializeError when a component contains an unencodable CR/LF
(ASTM_EMIT_UNENCODABLE_VALUE), or when d fails one of the three conditions
readback requires (ASTM_EMIT_INVALID_DELIMITERS). Like
encodeComponent this takes no record, so it never raises
ASTM_EMIT_TYPE_LETTER_COLLISION: encoding a record's type-letter field
through it will escape that letter away without objecting.
Example
import { serializeField, tokenizeRecord, CANONICAL_DELIMITERS } from "@cosyte/astm";
const fields = tokenizeRecord("R|1|^^^687|1&S&40", CANONICAL_DELIMITERS);
serializeField(fields[3]!); // "1&S&40"