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

@goliapkg/tokenrs-wasm

v2.1.0

Published

WASM bindings for the tiktoken BPE tokenizer

Readme

tiktoken-wasm

WebAssembly bindings for the tiktoken BPE tokenizer — run OpenAI-compatible tokenization directly in the browser or Node.js with near-native performance.

Build

# requires wasm-pack: cargo install wasm-pack
cd tiktoken-wasm
wasm-pack build --target web --release

Output is in pkg/ — a complete npm-ready package containing:

  • tiktoken_wasm.js — ES module with WASM loader
  • tiktoken_wasm_bg.wasm — compiled WASM binary (~3 MB)
  • tiktoken_wasm.d.ts — TypeScript type definitions

Usage

ES Module (Browser / Vite / webpack)

import init, {
  getEncoding,
  encodingForModel,
  estimateCost,
  getModelInfo,
  type Encoding,
} from 'tiktoken-wasm'

// initialize WASM module (required once, before any other calls)
await init()

// encode / decode
const enc: Encoding = getEncoding('cl100k_base')
const tokens: Uint32Array = enc.encode('hello world')
const text: string = enc.decode(tokens)   // "hello world"
const count: number = enc.count('hello world')  // 2

// by model name
const enc2 = encodingForModel('gpt-4o')

// cost estimation (USD)
const cost: number = estimateCost('gpt-4o', 1000, 500)

// model metadata
const info = getModelInfo('claude-opus-4')
// { id, provider, input_per_1m, output_per_1m, cached_input_per_1m, context_window, max_output }

// free WASM memory when done
enc.free()
enc2.free()

Bundler Configuration

Vite — add plugins to vite.config.ts:

import wasm from 'vite-plugin-wasm'
import topLevelAwait from 'vite-plugin-top-level-await'

export default defineConfig({
  plugins: [wasm(), topLevelAwait()],
})

webpack 5 — enable WASM experiments in webpack.config.js:

module.exports = {
  experiments: {
    asyncWebAssembly: true,
  },
}

Next.js — add to next.config.js:

module.exports = {
  webpack: (config) => {
    config.experiments = { ...config.experiments, asyncWebAssembly: true }
    return config
  },
}

API Reference

getEncoding(name: string): Encoding

Get a tokenizer by encoding name. Supported: cl100k_base, o200k_base, p50k_base, p50k_edit, r50k_base.

encodingForModel(model: string): Encoding

Get a tokenizer by OpenAI model name (e.g. gpt-4o, o3-mini, gpt-3.5-turbo).

Encoding

| Method | Returns | Description | |--------|---------|-------------| | encode(text) | Uint32Array | Encode text to token ids | | encodeWithSpecialTokens(text) | Uint32Array | Encode with special token recognition | | decode(tokens) | string | Decode token ids to text | | count(text) | number | Count tokens (faster than encode().length) | | name | string | Encoding name (getter) | | free() | void | Release WASM memory |

estimateCost(modelId, inputTokens, outputTokens): number

Estimate API cost in USD. Supports OpenAI, Anthropic Claude, and Google Gemini models.

getModelInfo(modelId): object

Get model metadata: pricing, context window, max output tokens.

Supported Models (pricing)

| Provider | Models | |----------|--------| | OpenAI | gpt-4o, gpt-4o-mini, o1, o3, o4-mini, gpt-4-turbo, gpt-4, gpt-3.5-turbo, embeddings | | Anthropic | claude-opus-4, claude-sonnet-4, claude-3.5-haiku, claude-3.5-sonnet, claude-3-opus, claude-3-haiku | | Google | gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash, gemini-1.5-pro, gemini-1.5-flash |

Demo

See examples/react-app for a complete Vite + React demo application.

License

MIT