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

toonformer

v0.2.0

Published

Intelligent TOON optimization with cost analysis and integrations, built on @toon-format/toon.

Readme

toonformer

Smart TOON optimization with cost analysis and integrations — built on the official @toon-format/toon encoder.

Why

Reduce LLM token costs by converting tabular JSON payloads to TOON text when it helps — and avoid TOON when it hurts (deep nesting). This package adds:

  • Token counting and multi-scale cost estimates (per-request, per1K, per100K, per1M)
  • Smart recommendations with structure analysis and actionable suggestions
  • Textual TOON output compatible with the official spec
  • Streaming, middleware, and CLI for easy adoption

Install

npm install toonformer

Quick Start

import { toTOON, analyzeSavings, smartConvert } from 'toonformer';

// Convert to textual TOON
const toonText = toTOON(data);

// Analyze token and cost impact (OpenAI example)
const analysis = analyzeSavings(data, {
  cost: { provider: 'openai', model: 'gpt-4o-mini' },
  conciseSummary: true
});
console.log(analysis.summary);

// Smart conversion with automatic fallback
const result = smartConvert(data, { autoDetect: true, threshold: 0.2, fallback: 'json' });
if (result.format === 'toon-text') {
  // Send toon text to your LLM/pipeline
}

CLI

# Analyze (includes summary line with --summary)
npx toonformer analyze ./tests/test2.json --provider openai --model gpt-4o-mini --summary

# Convert to textual TOON
npx toonformer convert ./tests/test2.json --output ./results/test2.toon

Examples (measured)

  • Deeply nested JSON (test2.json)

    • Tokens: JSON 920 vs TOON 1401 (+52.3%)
    • Cost (OpenAI input @ $0.15 / 1M): extra $72.15 per 1M requests
    • Verdict: keep JSON
    • Reason: Deep nesting (depth 12 > threshold 3) adds whitespace/overhead
  • Flat(ish) users example (users.flat.json)

    • Tokens: JSON 53 vs TOON 33 (−37.7%)
    • Cost: saves ~$3.00 per 1M requests
    • Note: Best savings are achieved when your top-level data is an array of objects with consistent keys. Nesting under another object may limit the savings shown here.

When TOON helps (and when it doesn’t)

  • Helps: Arrays of objects with consistent keys (tabular), modest depth (≤3)
  • Avoid: Deeply nested structures (>3), heterogeneous row keys, large unstructured text

Recommendation details

analyzeSavings() returns:

  • tokens: { jsonTokens, toonTokens, tokenDiff, diffPct }
  • cost: { perRequest, per1K, per100K, per1M, normalized }
  • structure: { maxDepth, arrayCount, rowCount, keyConsistency, depthThreshold, exceededBy, verdict }
  • recommendation: { recommended, reason, suggestions, alternatives }
  • summary (optional): one-line CI-friendly string when conciseSummary: true

Acknowledgements

  • Built on the official TOON library: @toon-format/toon (MIT). Thanks to the maintainers for providing the canonical encoder/decoder.

License

MIT