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

lttb-js

v1.0.6

Published

High-performance, memory-efficient LTTB implementation, designed to downsample massive datasets with thousands, millions, or hundreds of millions of points while keeping memory usage to a minimum.

Readme

lttb-js

NPM Version

lttb-js is a high-performance, memory-efficient implementation of the Largest-Triangle-Three-Buckets (LTTB) algorithm, designed to downsample massive datasets with thousands, millions, or hundreds of millions of points while keeping memory usage to a minimum.

Performance tests

| Container | Dataset | Memory limit | |-----------|-------------------------|--------------| | node:slim | 100,000,000 (4.2 GB) | 50 MB | | node:slim | 1,000,000,000 (42 GB) | 150 MB |

Installation

npm install lttb-js

Usage

For small datasets with a few thousand elements or less, use the lttb function.

import { lttb } from 'lttb-js';

const dataset = [
  { x: 1, y: 23.32 },
  { x: 2, y: 98.42 },
  { x: 3, y: 15.45 },
  ...
  // 10,000 items
];

const threshold = 100;

const result = await lttb(dataset, threshold);

Streaming

For large datasets with millions or hundreds of millions of elements, you should use lttbStream to keep memory usage to a minimum.

import { lttbStream } from 'lttb-js';

const datasetLength = 1_023_435;
const threshold = 1334;
const batchSize = 20_000;

const result = await lttbStream(
  datasetLength, 
  threshold, 
  batchSize, 
  async function* (offset, size) {
    // Stream the data from an API, a database, or another source
    const stream = await streamDataFromDatabase(offset, size);

    for await (const item of stream) {
      yield { x: item.x, y: item.y };
    }
  }
);

The lttbStream function loads the data as it processes it, preventing load the whole dataset into memory. Every time it is ready for more data, it calls the callback function to fetch the next batch.

Batch requests

If your API or database doesn't support streaming, you can fetch the data normally and pass it to lttbStream in the following way:

const result = await lttbStream(..., async function* (offset, size) {
  // Fetch the data from an API, a database, or another source
  const data = await fetchDataFromDatabase(offset, size);

  for (const item of data) {
    yield { x: item.x, y: item.y };
  }
});

Notice that here we are using a normal for loop and not for await.

Or, if your data already arrives in the { x: number, y: number } format, you can pass it directly using yield*:

const result = await lttbStream(..., async function* (offset, size) {
  // Fetch the data from an API, a database, or another source
  const data = await fetchDataFromDatabase(offset, size);
  yield* data;
});

Reference

lttb

lttb(items: Point[], threshold: number): Promise<Point[]>
  • items: List of data points to process.
  • threshold: The number of points to return.

lttbStream

lttbStream(
  length: number, 
  threshold: number, 
  batchSize: number, 
  streamFunction: (offset: number, size: number) => AsyncGenerator<Point, void>
): Promise<Point[]>
  • length: The total length of the dataset.
  • threshold: The number of points to return.
  • batchSize: The number of items to load each time.
  • streamFunction: Function called to load more data.

Point

interface Point {
  x: number;
  y: number;
}