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

ltcode

v1.0.4

Published

Luby Transform Code implementation.

Downloads

27

Readme

Luby Transform Codes

This project is a TypeScript implementation of Luby Transform (LT) codes, a type of forward error correction (FEC) code. LT codes are fountain codes, meaning they can generate a potentially limitless stream of encoded blocks from a fixed set of source blocks. The original data can be reconstructed from any subset of the encoded blocks, as long as the number of received blocks is slightly larger than the number of source blocks.

How it Works

The project is divided into several key components:

Encoder (encode.ts)

The Encoder takes a string of data as input and generates an infinite stream of encoded blocks. Each block is a string containing the following information:

  • <length>: The length of the original data.
  • <size>: The size of each block.
  • <seed>: The seed used to generate the random numbers for this block.
  • <data>: The encoded data (XOR sum of selected source blocks).

Decoder (decode.ts)

The Decoder takes the encoded blocks as input and reconstructs the original data. It does this by building a graph of the relationships between the blocks and then using a process of elimination (Gaussian elimination-like process) to solve for the original data blocks.

Pseudo-Random Number Generator (PRNG) (prng.ts)

This module implements a custom PRNG used by both the Encoder and Decoder to ensure that the same source blocks are sampled for a given seed. It also handles the degree distribution (how many source blocks contribute to an encoded block) based on the robust soliton distribution.

Utilities (utils.ts)

This file provides helper functions for converting between BigInt (used for block data) and Buffer (byte arrays), handling both big-endian and little-endian byte orders.

How to Use

To use the project, you can run the example.ts file:

pnpm install
pnpm start

This will encode and decode a sample message and print the result to the console.

API Reference

Encoder Class

  • constructor(size: number = 100): Initializes the encoder with an optional block size.
  • encode(data: string): Generator<string>: A generator function that yields encoded blocks as strings.

Decoder Class

  • constructor(): Initializes the decoder.
  • decode(data: string): boolean: Consumes an encoded block string. Returns true if decoding is complete, false otherwise.
  • result(): Buffer: Returns the reconstructed original data as a Buffer. Throws an error if decoding is not yet complete.

PRNG Class

  • constructor(numBlocks: number, state: number): Initializes the PRNG with the total number of source blocks and an initial state (seed).
  • sample_source_blocks(state: number | null): [number, Set<number>]: Samples a set of source block indices and returns the seed used and the set of indices. If state is provided, it updates the PRNG's internal state.