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

loft-codec

v1.1.4

Published

LOFT: Language Optimized Format for Tokenization - A token-efficient serialization format for LLMs.

Readme

LOFT - Language Optimized Format for Tokenization

npm version License: MIT

A TypeScript library for serializing JavaScript objects into the LOFT format - a highly readable, token-efficient serialization format optimized for LLMs and data transmission.

🌟 Features

  • Primitive Types: Booleans (+/-), Null (~), Numbers, Strings
  • Smart String Handling: Automatic backtick wrapping for special characters and whitespace
  • Array Formats: Simple lists and matrix format for structured data
  • Object Serialization: Nested objects with readable indentation
  • Pure LOFT Format: Indentation-based structure (default) or legacy braced format
  • Matrix Format: Efficient representation of arrays with identical keys
  • Customizable Indentation: Configure spacing to your preference
  • Recursive Processing: Handles deeply nested structures
  • TypeScript Support: Full type definitions included
  • Zero Dependencies: Lightweight and fast
  • Multiple Import Styles: Named imports, default imports, or class instantiation

📦 Installation

npm install loft-codec

🚀 Quick Start

LOFT supports multiple import styles to fit your coding preferences:

Style A: Named Import (Recommended)

import { stringify } from "loft-codec";

const data = {
  name: "Alice",
  age: 30,
  active: true,
  balance: null,
};

console.log(stringify(data));

Style B: Default Import with Static Method

import Loft from "loft-codec";

const data = { name: "Bob", age: 25 };
const loftString = Loft.stringify(data);
console.log(loftString);

Style C: Class Instantiation

import Loft from "loft-codec";

const loft = new Loft();
const data = { name: "Charlie", age: 28 };
console.log(loft.stringify(data));

Output (Pure LOFT Format - Default):

name: Alice
age: 30
active: +
balance: ~

⚡ Key Example: See the Difference

Here's a real-world example showing LOFT's advantages over JSON:

import { stringify } from "loft-codec";

// Typical API response with user data
const users = [
  { id: 1, name: "Alice", active: true, role: "admin" },
  { id: 2, name: "Bob", active: false, role: "user" },
  { id: 3, name: "Charlie", active: true, role: "user" },
];

console.log("JSON:", JSON.stringify(users, null, 2));
console.log("\nLOFT:", stringify(users));

JSON Output (263 characters):

[
  {
    "id": 1,
    "name": "Alice",
    "active": true,
    "role": "admin"
  },
  {
    "id": 2,
    "name": "Bob",
    "active": false,
    "role": "user"
  },
  {
    "id": 3,
    "name": "Charlie",
    "active": true,
    "role": "user"
  }
]

LOFT Output (89 characters - 66% smaller!):

[id, name, active, role] {
  1, Alice, +, admin;
  2, Bob, -, user;
  3, Charlie, +, user
}

Note: Matrix format uses braces {} even in pure LOFT mode for clarity in tabular data.

📖 Format Rules

Booleans

  • true+
  • false-

Null

  • null~

Strings

  • Simple strings (no special chars): hello, world, Alice
  • Strings with special characters (:, {, }, ,, ;, [, ]): Wrapped in backticks
    • Example: key:value`key:value`
    • Example: Hello, World!`Hello, World!`

Numbers

  • Rendered as-is: 42, 3.14, -10, 0.001

Arrays

Simple List Format

When an array contains simple values or mixed types:

[1, 2, 3, 4, 5];

LOFT Output:

{
  1;
  2;
  3;
  4;
  5
}

Matrix Format (Array of Objects with Identical Keys)

When an array contains objects with the same keys, LOFT uses an optimized tabular format:

[
  { name: "Alice", age: 30 },
  { name: "Bob", age: 25 },
];

LOFT Output:

[name, age] {
  Alice, 30;
  Bob, 25
}

Benefits:

  • Reduces redundancy
  • More readable for tabular data
  • Significantly fewer tokens

Objects

Objects are represented with clear key-value pairs and proper indentation.

Pure LOFT Format (Default)

Indentation-based structure without braces:

{
  user: 'John',
  settings: {
    theme: 'dark',
    notifications: true
  }
}

LOFT Output:

user: John
settings:
  theme: dark
  notifications: +

Legacy Format (with useBraces: true)

Braced structure for backward compatibility:

{
  user: John
  settings {
    theme: dark
    notifications: +
  }
}

💡 Examples

Basic Serialization

import { stringify } from "loft-codec";

const apiResponse = {
  status: "success",
  code: 200,
  data: {
    users: [
      { id: 1, username: "alice123", verified: true },
      { id: 2, username: "bob_smith", verified: false },
    ],
    total: 2,
  },
  errors: null,
};

console.log(stringify(apiResponse));

Output (Pure LOFT Format):

status: success
code: 200
data:
  users:
    [id, username, verified] {
      1, alice123, +;
      2, bob_smith, -
    }
  total: 2
errors: ~

Nested Structures

const company = {
  name: "TechCorp",
  founded: 2020,
  active: true,
  address: {
    street: "123 Main St",
    city: "San Francisco",
    country: "USA",
  },
};

console.log(stringify(company));

Output (Pure LOFT Format):

name: TechCorp
founded: 2020
active: +
address:
  street: `123 Main St`
  city: San Francisco
  country: USA

Complex Data with Arrays

const dataset = {
  metadata: {
    version: "2.0",
    timestamp: 1700000000,
  },
  records: [
    { id: 1, type: "A", value: 100, active: true },
    { id: 2, type: "B", value: 200, active: false },
    { id: 3, type: "A", value: 150, active: true },
  ],
  tags: ["important", "reviewed", "archived"],
};

console.log(stringify(dataset));

Output (Pure LOFT Format):

metadata:
  version: `2.0`
  timestamp: 1700000000
records:
  [id, type, value, active] {
    1, A, 100, +;
    2, B, 200, -;
    3, A, 150, +
  }
tags: {
  important;
  reviewed;
  archived
}

🎯 Design Principles

  1. Token Efficiency: Minimize token usage for LLM contexts
  2. Readability: Human-readable format with proper indentation
  3. Lossless: Preserve all data during serialization
  4. Type Safety: Clear type representation for all JavaScript types
  5. Smart Formatting: Automatic detection of optimal array format
  6. Simplicity: Minimal syntax with maximum clarity

🤔 Why LOFT?

Traditional JSON can be verbose and token-inefficient. LOFT optimizes for:

| Feature | JSON | LOFT | Savings | | --------------- | ------------------- | ----------------- | ------- | | Boolean true | true (4 chars) | + (1 char) | 75% | | Boolean false | false (5 chars) | - (1 char) | 80% | | Null value | null (4 chars) | ~ (1 char) | 75% | | Simple strings | "hello" (7 chars) | hello (5 chars) | 29% | | Object keys | "key": (6 chars) | key: (4 chars) | 33% |

Additional Benefits:

  • Matrix format for arrays reduces redundancy in tabular data
  • No quotes needed for simple strings (no special characters)
  • Cleaner syntax improves human readability
  • Smaller payload size for data transmission

Use Cases

  • 🤖 LLM Prompts: Reduce token count in AI conversations
  • 📡 Data Transmission: Smaller payload sizes
  • 📝 Configuration Files: More readable than JSON
  • 📊 Logging: Compact and human-friendly logs
  • 💾 Data Storage: Efficient serialization format