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

fast-varint-codec

v1.0.1

Published

High-performance variable-length integer codec using fixed sizes (1, 2, 4, 8 bytes). The first 2 bits encode length, enabling fast, branch-efficient decoding. Uses simple bitwise ops and BigInt for 64-bit support. Matches low-level performance (comparable

Readme

fast-varint-codec

High-performance variable-length integer codec. Uses fixed sizes of 1, 2, 4, or 8 bytes — the first 2 bits of each encoded value indicate the byte length, enabling fast and branch-efficient decoding without scanning byte-by-byte.

Features

  • Fixed widths: 1, 2, 4, or 8 bytes — no loops, pure bitwise ops
  • 64-bit support via BigInt
  • Dual package: ESM + CommonJS
  • TypeScript types included
  • Zero dependencies

Encoding scheme

| Value range | Bytes | Leading bits | | ---------------------- | ----- | ------------ | | 0 – 63 | 1 | 00 | | 64 – 16 383 | 2 | 01 | | 16 384 – 1 073 741 823 | 4 | 10 | | 1 073 741 824 – 2⁶⁴−1 | 8 | 11 |

Installation

npm install fast-varint-codec

Usage

ESM

import { encodeTo, decodeFrom, MAX_VARINT_SIZE } from "fast-varint-codec";

CommonJS

const { encodeTo, decodeFrom, MAX_VARINT_SIZE } = require("fast-varint-codec");

API

encodeTo(buf, value, offset?): number

Encodes value into buf at offset (default 0). Returns the number of bytes written (1, 2, 4, or 8).

  • bufUint8Array or any array-like buffer
  • valuenumber for values ≤ 1 073 741 823, or bigint for larger values
  • offset — byte offset (default: 0)
const buf = new Uint8Array(8);

encodeTo(buf, 42); // 1 byte
encodeTo(buf, 1000); // 2 bytes
encodeTo(buf, 500000); // 4 bytes
encodeTo(buf, 5000000000n); // 8 bytes, pass as BigInt

decodeFrom(buf, offset?, len?): number | bigint

Decodes a varint from buf at offset (default 0). Returns a number for 1–4 byte values, or a bigint for 8-byte values.

  • len — optional object; after the call, len.length contains the number of bytes consumed
const buf = new Uint8Array(8);
encodeTo(buf, 1000);

const len = { length: 0 };
const value = decodeFrom(buf, 0, len);
console.log(value); // 1000
console.log(len.length); // 2

MAX_VARINT_SIZE(): number

Returns 8 — the maximum number of bytes a single encoded value can occupy. Useful for pre-allocating buffers.

const buf = new Uint8Array(MAX_VARINT_SIZE());

License

ISC