TOON format parser/encoder with TOON+ extensions for LLM token efficiency
npm install @programsmagic/toon-formatTOON format parser/encoder with TOON+ extensions for LLM token efficiency.
``bash`
npm install @toon/formator
pnpm add @toon/formator
yarn add @toon/format
`typescript
import { encodeToon } from '@toon/format';
const json = {
user: {
id: 123,
name: 'Ada',
tags: ['reading', 'gaming'],
active: true
}
};
const toon = encodeToon(json);
console.log(toon);
`
`typescript
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);
`
`typescript
import { encodeToon } from '@toon/format';
const toon = encodeToon(json, {
toonPlus: true,
includeIndex: true,
includeMetadata: true,
includeComments: true
});
`
`typescript`
const toon = encodeToon(json, {
minimize: true // Strip all whitespace for pure model use
});
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
Parse TOON format to JSON.
Options:
- delimiter (string): Expected delimiteruseLengthMarkers
- (boolean): Use length markersvalidateIndex` (boolean): Validate structural index
-
MIT