npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tooner

v0.1.5

Published

Token-efficient serialization for LLMs - Convert JSON/YAML/TOML to TOON format

Readme

tooner

npm version License: MIT

Token-efficient serialization for LLMs - Convert JSON/YAML/TOML to TOON format

Installation

npm install tooner

# Or with other package managers
pnpm add tooner
yarn add tooner

What is TOON?

Token-Oriented Object Notation (TOON) is a compact, human-readable serialization format designed for passing structured data to Large Language Models with significantly reduced token usage (typically 30-60% fewer tokens than JSON).

TOON's sweet spot is uniform arrays of objects – multiple fields per row, same structure across items. See the official specification for complete details.

Usage

Core API (Object ↔ TOON)

import { encode, decode } from 'tooner';

const data = {
  users: [
    { id: 1, name: 'Alice', role: 'admin' },
    { id: 2, name: 'Bob', role: 'user' },
  ],
};

// Encode to TOON
const toon = encode(data);
console.log(toon);
// Output:
// users[2]{id,name,role}:
//   1,Alice,admin
//   2,Bob,user

// Decode from TOON
const decoded = decode(toon);
// Returns original data structure

Format Converters (Tree-Shakable)

// JSON ↔ TOON
import { encode, decode } from 'tooner/json';

const jsonString = '{"name":"Alice","age":30}';
const toon = encode(jsonString);

// YAML ↔ TOON
import { encode as yamlEncode } from 'tooner/yaml';

const yamlString = 'name: Alice\nage: 30';
const toon = yamlEncode(yamlString);

// TOML ↔ TOON
import { encode as tomlEncode } from 'tooner/toml';

const tomlString = 'name = "Alice"\nage = 30';
const toon = tomlEncode(tomlString);

CLI

# Encode JSON to TOON
npx tooner encode input.json -o output.toon

# Encode YAML to TOON
npx tooner encode input.yaml -f yaml -o output.toon

# Decode TOON to JSON
npx tooner decode input.toon -o output.json

# Decode TOON to YAML
npx tooner decode input.toon -f yaml -o output.yaml

Current Status

✅ Implemented

  • ✅ Project structure with tree-shakable exports
  • ✅ TypeScript configuration with strict mode
  • ✅ Build system (tsup) with dual package support (ESM + CJS)
  • ✅ CLI tool with commander
  • ✅ Format converter structure (JSON, YAML, TOML)
  • Complete TOON Encoder:
    • Primitive values (strings, numbers, booleans, null)
    • Objects and nested objects
    • Inline arrays: tags[3]: a,b,c
    • List format with hyphens for mixed arrays
    • Tabular format for uniform object arrays
    • Root-level arrays (all formats)
    • Alternative delimiters (comma, tab, pipe)
    • Proper key quoting and escaping
    • Whitespace handling
  • Complete TOON Decoder (363/363 tests passing - 100%):
    • Parse TOON indentation structure
    • Parse inline arrays with all delimiters
    • Parse list format with nested objects
    • Parse tabular format
    • Handle all primitive types (including scientific notation)
    • Path expansion with expandPaths: 'safe' option
    • Strict mode with indentation validation
    • Custom indent sizes
    • Validate array lengths and field counts
    • Error handling with line numbers
    • Escape sequence handling
  • ✅ Test infrastructure with Vitest
  • ✅ Official TOON test fixtures (363/363 passing - 100%)
  • ✅ Security hardened (ReDoS vulnerabilities patched)

📋 TODO

  • Documentation:
    • Comprehensive API documentation
    • More usage examples
    • Performance benchmarks
    • Comparison with JSON/YAML/TOML

Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Build
pnpm build

# Lint
pnpm lint

# Format
pnpm format

Bundle Sizes (Estimated)

Tree-shakable design ensures you only bundle what you use:

  • tooner (core): ~4KB
  • tooner/json: ~4KB (no extra deps)
  • tooner/yaml: ~20KB (includes yaml parser)
  • tooner/toml: ~15KB (includes toml parser)

Architecture

Tree-Shaking First

  • Each entry point is completely independent
  • No shared state between converters
  • Core has zero dependencies
  • Format parsers only imported when needed

File Structure

tooner/
├── src/
│   ├── core/
│   │   ├── encoder.ts     # TOON encoder
│   │   ├── decoder.ts     # TOON decoder (TODO)
│   │   └── types.ts       # Shared types
│   ├── json.ts            # Entry: tooner/json
│   ├── yaml.ts            # Entry: tooner/yaml
│   ├── toml.ts            # Entry: tooner/toml
│   └── index.ts           # Entry: tooner
├── cli/
│   └── index.ts           # CLI tool
└── tests/
    ├── fixtures/          # Official TOON test fixtures
    ├── unit/              # Unit tests
    ├── integration/       # Integration tests
    └── performance/       # Benchmarks

Contributing

This project follows the official TOON specification. Contributions are welcome! Please see issues tagged with "good first issue" or "help wanted".

License

MIT © 2025

Resources