toon-package

@programsmagic/toon-format

TOON format parser/encoder with TOON+ extensions for LLM token efficiency.

Installation

npm install @programsmagic/toon-format
# or
pnpm add @programsmagic/toon-format
# or
yarn add @programsmagic/toon-format

Usage

Encode JSON to TOON

import { encodeToon } from '@programsmagic/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 '@programsmagic/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 '@programsmagic/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:

parseToon(toon, options?)

Parse TOON format to JSON.

Options:

License

MIT