tooner
Version:
Token-efficient serialization for LLMs - Convert JSON/YAML/TOML to TOON format
79 lines (77 loc) • 2.13 kB
text/typescript
/**
* TOON value types
*/
type ToonPrimitive = string | number | boolean | null;
type ToonValue = ToonPrimitive | ToonObject | ToonArray | ToonValue[];
interface ToonObject {
[key: string]: ToonValue;
}
type ToonArray = ToonValue[];
/**
* Encoder options
*/
interface EncodeOptions {
/**
* Enable strict validation during encoding
*/
strict?: boolean;
/**
* Indentation (default: 2)
* - number: Number of spaces
* - string: Custom indentation string
*/
indent?: number | string;
/**
* Array delimiter (default: comma)
* - ',' - Comma delimiter (default)
* - '\t' - Tab delimiter
* - '|' - Pipe delimiter
*/
delimiter?: ',' | '\t' | '|';
/**
* Key folding mode (default: none)
* - false/undefined: No key folding
* - 'safe': Fold single-key chains into dotted paths
*/
keyFolding?: false | 'safe';
/**
* Maximum depth for key folding (default: Infinity when keyFolding is 'safe')
* - 0: No folding
* - n: Fold up to n levels
*/
flattenDepth?: number;
}
/**
* Decoder options
*/
interface DecodeOptions {
/**
* Enable strict validation during decoding
*/
strict?: boolean;
/**
* Indentation size (default: 2)
*/
indent?: number;
/**
* Path expansion mode (default: 'off')
* - 'off': Keep dotted keys literal
* - 'safe': Expand identifier-only dotted keys
*/
expandPaths?: 'off' | 'safe';
}
/**
* Errors
*/
declare class ToonError extends Error {
line?: number | undefined;
column?: number | undefined;
constructor(message: string, line?: number | undefined, column?: number | undefined);
}
declare class ToonEncodeError extends ToonError {
constructor(message: string);
}
declare class ToonDecodeError extends ToonError {
constructor(message: string, line?: number, column?: number);
}
export { type DecodeOptions as D, type EncodeOptions as E, type ToonValue as T, type ToonObject as a, type ToonArray as b, type ToonPrimitive as c, ToonError as d, ToonEncodeError as e, ToonDecodeError as f };