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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bitarray/es6

v1.2.0

Published

An ES6 BitArray class for easy and native-like operations on sequences of bits

Downloads

29

Readme

@bitarray/es6

GitHub package.json dynamic

A BitArray class for easy and native-like operations on sequences of bits.

Rationale

The library implements ArrayBuffers behind the hood. This allows for:

  • optimal memory usage: each bit is effectively coded in just one bit in memory, as opposed to being coded as, e.g. booleans or integers in regular arrays.

  • efficient bitwise operations: operations treat 32 bits at once, as opposed to dealing with entries one by one in regular arrays.

:bulb: It comes at the cost that accessing a single bit at a given index will be slightly more expensive than accessing the value stored in a regular array: indeed, the interesting bit needs to be extracted once a Uint32 value has been found first.

Having said that, in the very vast majority of cases, any difference either way should be unnoticeable; and you may very well opt to use this library for the sole reason that it provides a convenient native-like interface for your needs.

Compatibility

compatibility

The library relies on the Proxy object, which is an ES6 (aka ES2015) feature. It can NOT be polyfilled (to the extent it is used by the library).

Note: standard TypedArray is also a feature of ecmascript ES6.

Installation

npm version

npm install @bitarray/es6

or

yarn add @bitarray/es6

Usage

Usage is same as for any standard typed array. You may check the MDN documentation for details. This is because the BitArray object extends @bitarray/typedarray. Check it for details.

It adds bitwise operations on top.

Instantiating

import BitArray from "@bitarray/es6"

const bits = BitArray.from("11001010");

const otherbits = new BitArray(12); // 12 bits, the values of which default to zero.

Bitwise operations

bits.count; // === 4; number of bits set to 1.

// same as bits.and(otherbits)
(bits)['&'](otherbits); // an instance holding a sequence of eight zeros

// same as bits.or(otherbits)
(bits)['|'](otherbits); // 11001010

// same as bits.xor(otherbits)
(bits)['^'](otherbits); // 11001010

Iterating

for (let i=0; i<bits.length; i++)
  // do something with bits[i]

bits.forEach((val, i, arr) => { /* do something */ });

for (let i in bits)
  // do something with bits[i]

for (let bit of bits)
  // do something with bit

Indexes & values

Object.keys(bits);    // [0, 1, 2, 3, 4, 5, 6, 7]
Object.values(bits);  // [1, 1, 0, 0, 1, 0, 1, 0]
Object.entries(bits); // [["0", 1], ["1", 1], ["2", 0], ["3", 0], ...]

License

license