@programsmagic/toon-format
v0.1.0
Published
TOON format parser/encoder with TOON+ extensions for LLM token efficiency
Maintainers
Readme
@toon/format
TOON format parser/encoder with TOON+ extensions for LLM token efficiency.
Installation
npm install @toon/format
# or
pnpm add @toon/format
# or
yarn add @toon/formatUsage
Encode JSON to TOON
import { encodeToon } from '@toon/format';
const json = {
user: {
id: 123,
name: 'Ada',
tags: ['reading', 'gaming'],
active: true
}
};
const toon = encodeToon(json);
console.log(toon);Parse TOON to JSON
import { parseToon } from '@toon/format';
const toon = `user id 123 name Ada tags [reading gaming] active true`;
const result = parseToon(toon);
console.log(result.data);TOON+ Extensions
import { encodeToon } from '@toon/format';
const toon = encodeToon(json, {
toonPlus: true,
includeIndex: true,
includeMetadata: true,
includeComments: true
});Ultra-Minimization Mode
const toon = encodeToon(json, {
minimize: true // Strip all whitespace for pure model use
});API Reference
encodeToon(data, options?)
Encode JSON to TOON format.
Options:
minimize(boolean): Strip all whitespacetoonPlus(boolean): Include TOON+ extensionsincludeIndex(boolean): Include structural indexincludeMetadata(boolean): Include metadataincludeComments(boolean): Include field commentsdelimiter(string): Custom delimiter (default: space)useLengthMarkers(boolean): Use length markers instead of delimiters
parseToon(toon, options?)
Parse TOON format to JSON.
Options:
delimiter(string): Expected delimiteruseLengthMarkers(boolean): Use length markersvalidateIndex(boolean): Validate structural index
License
MIT
