UNPKG

zon-format

Version:

ZON: The most token-efficient serialization format for LLMs - beats CSV, TOON, JSON, and all competitors

52 lines (51 loc) 1.53 kB
/** * Streaming Encoder for ZON format. * Uses Async Generators to process data chunk by chunk, suitable for large datasets. */ export declare class ZonStreamEncoder { private encoder; private hasWrittenHeader; private columns; constructor(); /** * Encodes a stream of objects into ZON format. * Assumes the stream consists of uniform objects (table format). * * @param source - Iterable or AsyncIterable of objects * @returns AsyncGenerator yielding ZON string chunks * @throws Error if the source contains non-object items */ encode(source: Iterable<any> | AsyncIterable<any>): AsyncGenerator<string>; /** * Formats a single value for ZON output. * * @param val - The value to format * @returns The formatted string */ private _formatValue; } /** * Streaming Decoder for ZON format. * Processes string chunks and yields parsed objects. */ export declare class ZonStreamDecoder { private decoder; private buffer; private columns; private isTable; constructor(); /** * Decodes a stream of ZON string chunks into objects. * * @param source - Iterable or AsyncIterable of string chunks * @returns AsyncGenerator yielding parsed objects */ decode(source: Iterable<string> | AsyncIterable<string>): AsyncGenerator<any>; /** * Parses a single row of ZON data. * * @param line - The line to parse * @returns Array of parsed values */ private _parseRow; }