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

@pacote/bloom-filter

v0.8.1

Published

Space-efficient probabilistic data structures.

Readme

@pacote/bloom-filter

version minified minified + gzip

A Bloom filter is a space-efficient probabilistic data structure that allows testing whether an element belongs to a set.

Bloom filters relax result accuracy for this efficiency. With Bloom filters, false positive matches are possible, but false negatives are not. That is to say, while it can tell you with certainty when an element is not in a set, any positive responses indicate only a possibility.

This false positive error rate can be lowered — but never completely eliminated — by increasing the size of the filter and/or the number of hashes computed for each element.

Installation

yarn add @pacote/bloom-filter

Usage

import { BloomFilter } from '@pacote/bloom-filter'

const filter = new BloomFilter({ size: 22056, hashes: 8 })

filter.add('foo')
filter.add('bar')

filter.has('foo') // -> true
filter.has('bar') // -> true
filter.has('baz') // -> false

BloomFilter<T extends { toString(): string }>

BloomFilter builds a data structure that may be used to test the membership of any String-serialisable value (i.e. an object which implements the toString() method).

Because a Bloom filter is so simple, it cannot handle removing elements. You may use a CountingBloomFilter for that.

The class constructor takes an Options object with the following properties:

  • size (number, required) determines the size of the filter in bits. The value is required and must not be negative.

  • hashes (number, required) sets the number of distinct hashes that need to be calculated. A higher number performs more slowly, but lowers the probability of false positives occuring. The value is required and must be a positive integer.

  • seed (number) sets the seed for the hashing function. The default is 0x00c0ffee.

  • filter (BloomFilter<T>) allows initialising the filter from an array of unsigned 32-bit integers.

Class instances may be serialised into JSON using JSON.stringify() for storage or for sending over the network. The JSON string can then be deserialised and fed back into the constructor to recreate the original Bloom filter.

add(element: T): void

The add() method mutates to filter to indicate that the provided serialisable element is present.

has(element: T): boolean

The has() method checks the filter for membership of the provided value. If false, it is guaranteed not to be present. Otherwise, there's the possibility of it being a false positive result.

CountingBloomFilter<T extends { toString(): string }>

CountingBloomFilter builds a data structure that may be used to test the membership of any String-serialisable value (i.e. an object which implements the toString() method). It's a generalisation of BloomFilter that counts the number of times an element was added to the set.

Unlike the simpler BloomFilter, this class supports element removal.

The class constructor takes an Options object with the following properties:

  • size (number, required) determines the number of filter counters. The value is required and must not be negative.

  • hashes (number, required) sets the number of distinct hashes that need to be calculated. A higher number performs more slowly, but lowers the probability of false positives occuring. The value is required and must be a positive integer.

  • seed (number) sets the seed for the hashing function. The default is 0x00c0ffee.

  • filter (BloomFilter<T>) allows initialising the filter from an array of unsigned 32-bit integers.

Class instances may be serialised into JSON using JSON.stringify() for storage or for sending over the network. The JSON string can then be deserialised and fed back into the constructor to recreate the original Bloom filter.

add(element: T): void

The add() method mutates to filter and increments its counters to indicate an instance of the element was added.

remove(element: T): void

The remove() method mutates to filter and decrements its counters to indicate an instance of the element was removed.

has(element: T): number

The has() method checks the filter for membership of the provided element and returns the possible number of times it was added to the filter.

As with regular Bloom filters, there is a possibility of the result being a false positive, meaning the element may have been added fewer times than the returned value indicates.

optimal(items: number, errorRate: number): Options

The optimal() helper function calculates the optimal Bloom filter size and hashes options based on the number of items in the filter (n) and the desired false positive error rate (ε).

The size of the filter, or m, is calculated with:

The number of hashes, or k, is determined by the formula:

Hashing algorithms

This class depends on xxhashjs for an implementation of the fast XXH64 non-cryptographic hashing algorithm to build and search the filter via enhanced double hashing.

License

MIT © Luís Rodrigues.