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

@lp-labs/roaring-ranges

v0.1.0

Published

Bounded uint32 interval-set algebra using sorted disjoint ranges. Despite the package name, NOT a Roaring bitmap or its binary format.

Readme

@lp-labs/roaring-ranges

Bounded uint32 interval-set algebra using sorted disjoint ranges. Despite the package name, NOT a Roaring bitmap or its binary format.

Install

npm install @lp-labs/roaring-ranges

Version 0.1.0. MIT. Zero runtime, peer, or sibling dependencies. Node >=18; browser-compatible ES2022 runtime without browser-global reads. ESM and CommonJS exports have separate matching declarations.

Quick start

import { RoaringRanges } from '@lp-labs/roaring-ranges';
const allocated = new RoaringRanges([
  [0, 10],
  [20, 30],
]);
const unavailable = new RoaringRanges([[5, 25]]);
const free = allocated.difference(unavailable);
if (free.cardinality !== 10 || !free.has(29)) throw new Error('ranges');
console.log(free.toRanges()); // [[0, 5], [25, 30]]

Contract, customization, errors and ownership

Uint32Range is a readonly [start,end) pair of integer endpoints: 0 <= start < end <= 2^32. The exclusive endpoint 2^32 is allowed, but membership values must be uint32 0..2^32-1. Empty/reversed intervals, fractions, NaN and out-of-domain values throw RangeError; malformed pair shapes throw TypeError. Full-domain cardinality 2^32 is exactly representable. Intervals never expand into individual members.

maxRanges defaults 100,000 and is an integer 0..1,000,000. It bounds RAW input pair count, even when they would merge, and final output range count of operations. Constructor copies, sorts by start and merges overlap/adjacency to canonical disjoint nonadjacent pairs. Empty input is allowed, including maxRanges zero.

union/intersection/difference return new sets using the LEFT operand's maxRanges budget; a result requiring more ranges throws RangeError and leaves both operands unchanged. Budget checks occur during monotonic normalized output construction; difference can require more ranges than either operand. Operations require another RoaringRanges. has uses binary search; rangeCount counts canonical pairs, cardinality sums represented integers. toRanges returns owned mutable pairs; mutating input/output cannot change stored ranges.

Constructor O(n log n), set algebra merge scans O(n+m) plus result construction/sort O(k log k) in the current implementation; has O(log n), cardinality O(n), snapshot O(n), storage O(n). No binary serialization, Roaring containers, portable Roaring compatibility, rank/select, or per-value bitmaps. The honest range representation is suited to contiguous runs, not sparse random bitsets.

Complete public declaration contract

Runtime exports and all exported types are listed below. Internal storage members are omitted. Optional settings are constructor/function options, not globals.

/** Half-open integer range; end may equal 2^32. This is NOT a Roaring bitmap format. */
export type Uint32Range = readonly [start: number, end: number];
export declare class RoaringRanges {
  constructor(ranges?: readonly Uint32Range[], maxRanges?: number);
  get rangeCount(): number;
  get cardinality(): number;
  has(value: number): boolean;
  toRanges(): [number, number][];
  union(other: RoaringRanges): RoaringRanges;
  intersection(other: RoaringRanges): RoaringRanges;
  difference(other: RoaringRanges): RoaringRanges;
}

Development

npm ci --offline
npm run build
npm run typecheck
npm test
npm run format:check

TypeScript ^5.9.3 and Prettier ^3.6.2 are development-only. Offline installation requires their locked packages already in the local npm cache. Build emits dist/esm and dist/cjs with separate declarations; tests exercise runtime behavior and bare-package ESM/CommonJS type consumers with negative checks. No publish step is needed to build or test.

Support

If this library is useful to you, consider supporting its maintenance with a donation via PayPal.

Author

Created by Libin Prasanth. Connect on LinkedIn for updates and discussion.