Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
extensible-bit-vector
Advanced tools
Readme
An extensible bit-vector implementation for Javascript.
import BitVector from 'extensible-bit-vector';
const vector = new BitVector(32);
vector.set(2);
vector.set(7);
vector.set(31);
const b1 = vector.get(2); // true
const b2 = vector.get(3); // false
const b3 = vector.get(7); // true
vector.set(42); // automatically grows bitvector to fit.
vector.clear(2);
vector.clear(3);
const b4 = vector.get(2); // false
const b5 = vector.get(3); // false
const str = vector.serialize(); // compressed bitvector in Base64 format
// Store str in db here
const newVector = new BitVector(str); // re-hydrate bitvector from database.
const b6 = newVector.get(2); // false
const b7 = newVector.get(31); // true
You get the idea.
This is a bitvector that only works on Node, not the browser. The reason is that it relies on the Node Buffer class for serialization to and from strings. If you never do any serialization then it will work in the browser, but I don't recommend it.
In memory, the data is stored as a Uint8Array vector, and every 8 bits are stored as each byte. I would have used Uint32Array but it's much easier to convert to and from Base64 using Uint8Array.
The serialization method is designed to produce an optimized storage implementation of the bitvector, using as little memory as possible while still being storable in your average document database. I'm sure there are better ways to optimize the storage, but none are going to be as compatible as this.
FAQs
An extensible bit-vector class for Javascript
The npm package extensible-bit-vector receives a total of 9 weekly downloads. As such, extensible-bit-vector popularity was classified as not popular.
We found that extensible-bit-vector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.