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

coil-js

v0.4.0

Published

COIL — Token-optimized structured data encoding for LLM pipelines. Compress JSON into compact, schema-aware blocks that reduce LLM token usage by 40-70%.

Readme

🧬 COIL — Compact Object Input Language

Token-optimized structured data encoding for LLM pipelines.

COIL transforms JSON data into a compact, schema-aware format that significantly reduces token usage while remaining fully lossless and reversible. It is designed for use in LLM context windows where every token counts.


Why COIL?

Standard JSON is verbose. When you send large arrays of records, logs, or telemetry data to an LLM, most of the tokens go toward repeating keys and common values — not actual information.

COIL detects table-shaped arrays, builds a value map for repeated entries, and encodes rows positionally. The result is a structure that carries the same meaning in far fewer tokens.


Installation

npm install coil-js

Quick Start

const coil = require("coil-js");
const fs = require("fs");

// Load your data
const data = JSON.parse(fs.readFileSync("data.json", "utf8"));

// Encode to COIL
const encoded = coil.encode(data);

// Decode back to original structure
const decoded = coil.decode(encoded);

// Get compression stats
const stats = coil.stats(data, encoded, decoded);
console.log(stats);

Note: encode() writes a coil_types.json file in your working directory to store column type metadata. decode() reads this same file to restore types correctly. Both calls must happen in the same directory.


CLI

After installing, use the coil command:

# Encode a JSON file
coil encode input.json output.json

# Decode a COIL-encoded file
coil decode encoded.json decoded.json

If no output file is specified, the result is written to out.json.


API Reference

coil.encode(data)

Encodes a JavaScript object or array into COIL format.

COIL automatically:

  • Detects arrays of objects (tables) and encodes them positionally
  • Builds a greedy value map (vmap) for repeated string values
  • Stores column types to coil_types.json in the working directory
  • Falls back to returning the original data if encoding would not reduce token count
const encoded = coil.encode(data);
// encoded is a plain JS object — safe to JSON.stringify and store

Returns: A COIL-encoded object with meta and body fields for table blocks, or the original structure where encoding provides no benefit.


coil.decode(encoded)

Restores original data from a COIL-encoded object.

Reads coil_types.json from the working directory to restore column types (numbers, booleans, nulls).

const decoded = coil.decode(encoded);

Returns: The original JavaScript structure.


coil.stats(original, encoded, decoded?)

Returns compression metrics comparing the original and encoded data.

const stats = coil.stats(original, encoded, decoded);
console.log(stats);

Example output:

{
  "original": { "chars": 18300, "bytes": 18300, "tokens": 4575, "words": 2900 },
  "encoded":  { "chars": 6200,  "bytes": 6200,  "tokens": 1550, "words": 1200 },
  "comparison": {
    "token_saving_percent": "66.10",
    "byte_saving_percent": "66.12",
    "twr_original": "1.577",
    "twr_encoded": "1.291"
  },
  "lossless": true
}

twr is the token-to-word ratio — a lower value means more information per token.

If you pass a decoded value as the third argument, stats will also run a lossless check and include the lossless boolean.


coil.isLossless(original, decoded)

Checks whether a decoded result semantically matches the original.

const ok = coil.isLossless(original, decoded);
// true or false

This does a row-by-row canonical comparison, so it is order-independent.


coil.verify(original, encoded)

Decodes the encoded data and runs isLossless in one step.

const { decoded, lossless } = coil.verify(original, encoded);

coil.saveStats(stats, filename?)

Saves a stats object to a JSON file. Default filename is coil_stats.json.

coil.saveStats(stats, "my_stats.json");

coil.info()

Returns metadata about the installed library.

coil.info();
// {
//   library: "coil-js",
//   version: "0.4.0",
//   ecosystem: "node",
//   purpose: "Token-optimized structured data encoding for LLMs"
// }

Full Example

const coil = require("coil-js");
const fs = require("fs");

const data = JSON.parse(fs.readFileSync("data.json", "utf8"));

// Encode
const encoded = coil.encode(data);
fs.writeFileSync("encoded.json", JSON.stringify(encoded, null, 2));

// Decode
const decoded = coil.decode(encoded);
fs.writeFileSync("decoded.json", JSON.stringify(decoded, null, 2));

// Verify and measure
const stats = coil.stats(data, encoded, decoded);
coil.saveStats(stats, "coil_stats.json");

console.log(`Token reduction: ${stats.comparison.token_saving_percent}%`);
console.log(`Lossless: ${stats.lossless}`);

How COIL Works

COIL identifies two patterns in JSON:

Table arrays — arrays where every element is an object (records). COIL extracts the keys into an ordered column list, maps repeated values to short tokens (V1, V2…), and serialises rows as delimited strings. The metadata block stores the column order, value map, and type registry.

Categorical string arrays — arrays of repeated string values. COIL wraps them as single-column tables and applies the same value-map compression.

For everything else (plain objects, mixed arrays, primitives), COIL recurses into the structure and encodes whatever sub-structures it can, leaving the rest unchanged.


Known Limitations

  • decode() depends on coil_types.json being present in the working directory. If you encode in one location and decode in another, copy the types file along with the encoded JSON.
  • Token counts in stats are estimated using a character-length heuristic (ceil(chars / 4)), not an actual tokenizer. Results are approximate.
  • COIL falls back to the original data when encoding would not reduce size, so not every JSON document will be compressed.

License

MIT


Author

Muthukumaran S & Bala Jothi Adithiya S — Creator of the COIL Protocol

Contact - [email protected] , [email protected]

If you use COIL in research, please cite it as:
COIL — Compact Object Input Language, 2026.