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

@light-merlin-dark/tok

v0.3.0

Published

Fast token estimation and cost calculation for enterprise LLMs with CLI support

Readme

████████╗ ██████╗ ██╗  ██╗
╚══██╔══╝██╔═══██╗██║ ██╔╝
   ██║   ██║   ██║█████╔╝
   ██║   ██║   ██║██╔═██╗
   ██║   ╚██████╔╝██║  ██╗
   ╚═╝    ╚═════╝ ╚═╝  ╚═╝

Blazingly fast token estimation and cost calculation for LLMs
NPM package & CLI • Zero deps • 85KB

Why TOK?

  • 85KB: Minimal footprint
  • Zero dependencies: No tiktoken, no heavy libs
  • Fast: Sub-microsecond estimation
  • Flexible: Bring your own pricing
  • Simple: Works immediately

Install

# As a package (recommended)
npm install @light-merlin-dark/tok

# Or globally for CLI
npm install -g @light-merlin-dark/tok

Quick Start

TypeScript/JavaScript:

import { CharDivEstimator, PriceTable, CostCalculator } from '@light-merlin-dark/tok';

// Estimate tokens
const estimator = new CharDivEstimator();
const tokens = estimator.estimate("Hello world"); // 3

// Calculate cost
const prices = new PriceTable();
const cost = CostCalculator.cost(tokens, prices.get('gpt-4o').prompt);
console.log(CostCalculator.formatCost(cost)); // $0.0000075

CLI:

# Estimate tokens
tok estimate "Hello world"
# Output: Tokens: 3

# With cost calculation
tok estimate "Hello world" --model gpt-4o
# Output: Tokens: 3, Cost: $0.0000075

Bring Your Own Pricing

In code:

const prices = new PriceTable({
  'gpt-4o': { prompt: 2.50, completion: 10.00 },
  'claude-3-opus': { prompt: 15.00, completion: 75.00 }
});

const cost = CostCalculator.cost(tokens, prices.get('gpt-4o').prompt);

Via CLI:

tok price set gpt-4o --input 2.50 --output 10.00
tok price set claude-3-opus -i 15.00 -o 75.00
tok price list

CLI config stored in ~/.tok/config.json

Accuracy

Tested against OpenAI's tiktoken: ~80% accurate (19.7% avg error). Fast heuristic estimation trades perfect accuracy for zero dependencies and speed. Good for cost budgeting, not exact billing.

CharDivEstimator:     chars/4 (fastest)
TiktokenEstimator:    word analysis + punctuation weighting (more accurate)

Cost Tracking

In code:

import { CostTracker, PriceTable } from '@light-merlin-dark/tok';

const tracker = new CostTracker();
const prices = new PriceTable();

// Track multiple requests
tracker.add('gpt-4o', 100, 50, prices.get('gpt-4o'));
tracker.add('claude-3-opus', 200, 100, prices.get('claude-3-opus'));

// Get totals
console.log(`Total: $${tracker.grandTotal().toFixed(6)}`);
console.log(`Duration: ${tracker.getDuration()}s`);

// Get detailed summary
const summary = tracker.getSummary();
console.log(summary.modelBreakdown);

Via CLI:

tok estimate "First prompt" --model gpt-4o --track
tok estimate "Second prompt" --model claude-3-opus --track
tok track summary
# Output: Total: $0.000123 across 2 models

License

MIT


Built by Robert E. Beckner III (Merlin)