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

namedbits

v1.0.0

Published

Type-safe bit field with named bits

Readme

NamedBits

run tests

namedbits is a TypeScript/JavaScript library implementing a bit field, with named bits for easier access.

Installation

Install namedbits into an existing project:

# npm
npm install --save namedbits

Usage

import { NamedBits } from "namedbits";

// create new bit field
const bits = new NamedBits(["aa", "bb", "cc"] as const);

// set a bit
bits.set("bb");

// get a bit
bits.get("bb");
// true

// get the bit field as a number
bits.toNumber();
// 2

// convert to JSON
JSON.stringify({ bits });
// '{"bits":"2"}'

// convert to JSON as an array
bits.setOptions({json: "array"});
JSON.stringify({ bits });
// '{"bits":["bb"]}'

// try to use an invalid field name
// this relies on "as const" when creating the bit field
bits.set("omega");
// <repl>.ts:10:10 - error TS2345: Argument of type '"omega"' is not assignable to parameter of type '"aa" | "bb" | "cc"'.
// 
// 10 bits.set("omega");
//             ~~~~~~~

Documentation

new NamedBits(names, options)

Creates a new bit field

Params

  • names - array of strings
    • The names of bits, starting at the first. Pass a constant array (e.g.: ["aa", "bb", "cc"] as const ) to have the names be type checked.
  • options - object
    • see NamedBits#setOptions(options)

NamedBits#get(name)

Returns the value of a bit identified by the name

NamedBits#set(name, value = true)

Sets the value of a bit, to true by default

NamedBits#clear(name)

Clears the value of a bit. Identical to .set(name, false)

NamedBits#toggle(name)

Toggles the value of a bit

NamedBits#setAll()

Sets all bits to true

NamedBits#clearAll()

Sets all bits to false

NamedBits#setOptions(options)

Customizes bit field's behavior Params

  • options - object
    • options.json - "string_list" | "string_bigint" | "array" | "number"
      • Changes the way the bit field is serialized by JSON.stringify()
      • string_list - list of set field names, separated by a comma
      • string_bigint - value of the bit field as a bigint, converted to a string
      • array - JSON array of set bit names
      • number - value of the bit field as a number
        • Note, this will throw an exception if there are more than 53 bits, since JavaScript's number type cannot safely handle integers larger than 2^53.

NamedBits#toArray()

Returns a list set bit names as an array of strings

NamedBits#toNumber()

Returns the value of the bit field as a number.

Note, this will throw an exception if there are more than 53 bits, since JavaScript's number type cannot safely handle integers larger than 2^53.

NamedBits#toBigInt()

Returns the value of the bit field as a bignum

NamedBits#toString()

Returns a list of set bit names separated by a comma

NamedBits#toJSON()

Helper method for JSON.stringify(), configured by options.json

License

MIT