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

@biorate/bit-array

v2.1.1

Published

Bit array class

Downloads

56

Readme

@biorate/bit-array

Bit array class — compact 31-bit storage with bit-level set/remove/get operations and value packing.

Features

  • 31-bit storage — bits 0–30 (avoids JS signed 32-bit sign bit).
  • set / remove / get — individual bit manipulation.
  • value() — pack selected bits into a compact number by position.
  • bits() — extract indices of set bits from a number.
  • toBinary() / toInt() / valueOf() — conversion helpers.
  • Static helperBitArray.bits(value) — extract set bit indices without an instance.
  • Zero dependencies — pure JS, no runtime libraries.

Installation

pnpm add @biorate/bit-array

No runtime dependencies.

Quick start

import { BitArray } from '@biorate/bit-array';

const bits = new BitArray();

bits.set(0);
bits.set(3);
bits.set(5);

console.log(bits.get(0));    // 1
console.log(bits.get(1));    // 0
console.log(bits.toInt());   // 41  (2^0 + 2^3 + 2^5)

bits.remove(3);
console.log(bits.toInt());   // 33  (2^0 + 2^5)

console.log(bits.toBinary()); // '100001'

Module reference

BitArray — Main class

import { BitArray } from '@biorate/bit-array';

Constructor

| Constructor | Description | |--------------------|----------------------------------| | new BitArray(value?) | Initialise with optional starting value (default 0). |

Static members

| Member | Signature | Description | |----------------|----------------------------------|--------------------------------------------| | BitArray.bits| (value: number) => number[] | Given a number, returns array of indices where bits are 1. |

Instance members

| Member | Signature | Description | |-------------|--------------------------------------------|----------------------------------------------| | set | (index: number, offset?: number): void | Set bit at index (optionally shifted by offset). Throws if index > 30. | | remove | (index: number): void | Clear bit at index. No-op if already 0. | | get | (index: number): 0 \| 1 | Read bit value. Throws if index > 30. | | value | (...bits: number[]): number | Pack multiple bits into a number: each bit at position i. | | bits | (value: number): number[] | Instance wrapper around BitArray.bits(). | | define | (value: number): void | Overwrite internal storage. | | clear | (): void | Reset to 0. | | toBinary | (): string | Binary string representation. | | toInt | (): number | Raw integer value. | | valueOf | (): number | JS coercion hook — delegates to toInt(). |

Usage patterns

Flag management

const READ = 0, WRITE = 1, EXECUTE = 2, DELETE = 3;

const permissions = new BitArray();
permissions.set(READ);
permissions.set(WRITE);
permissions.set(EXECUTE);

console.log(permissions.get(DELETE)); // 0

Packing bits into a compact value

// Extract bits 0 and 2, pack into result: bit0→pos0, bit2→pos1
const result = bits.value(0, 2);
// result = (get(0) << 0) | (get(2) << 1)

Architecture

BitArray
│
├── #value: number             Internal 32-bit storage (bits 0-30)
│
├── #checkIndex(index)         Guard: throw if index > 30
├── #get(index)                Raw read: (value & (1 << index)) ? 1 : 0
│
├── set(i, offset)             value |= 1 << (i + offset)
├── remove(i)                  if #get(i): value ^= 1 << i
├── get(i)                     #get(i)
├── value(...bits)             result |= (get(bit) << i) for each
├── bits(value)                 loop 0-30, push if value & (1 << i)
└── toBinary()                 value.toString(2)

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)