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

big-bit-mask

v2.0.4

Published

The infinite bitmask serializable into a base64-like, url-safe string.

Downloads

24

Readme

Big bit mask

NPM NPM downloads Test status Coverage Status Build status GitHub


When bits is not enough ...

This library implements a bitmask serializable into a base64-like, url-safe string.

Other platform compatibility

| Platform | Repository | Package | |-|-|-| | PHP | php-big-bit-mask | Packagist | | .NET | BigBitMask.NET | NuGet |

Install

> npm install big-bit-mask

or

> yarn add big-bit-mask

Usage

Module import

import { BigBitMask } from "big-bit-mask";

Or require:

var BigBitMask = require("big-bit-mask").BigBitMask;

Or simple script without anything else:

<html>
    <head>
        <script src="./node_modules/big-bit-mask/dist/big-bit-mask.es5.min.js"></script>
    </head>
    <body>
        <script>
            var BigBitMask = BIGBITMASK.BigBitMask;
        </script>
    </body>
</html>

What next?

Now we can create new empty bitmask

var bitmask = new BigBitMask();

or load it from string

var bitmask = new BigBitMask("CE3fG_gE-56");

//Let's see what inside now
var content = "";
for(var i = 0; i < 11 * 6; i++) { // Each character contains 6 bits, as in base64
    content += bitmask.get(i) ? "1" : "0";
}
console.info(content);

output: 010000001000111011111110011000111111000001001000011111100111010111

Then we can change some bits and get back our string representation

bitmask.set(65, false);
bitmask.set(64, false);
bitmask.set(63, false);
bitmask.set(61, false);

bitmask.set(19, false);
bitmask.set(5, true);

console.info(bitmask.toString());

output: iE3dG_gE-5

But what if I want to have a named flags?

You can extend BigBitMask with your model:

class MyCoolCheckboxes extends BigBitMask {
    static get CHECKBOX_0() { return 0; }
    static get CHECKBOX_1() { return 1; }
    static get CHECKBOX_2() { return 2; }
    static get CHECKBOX_3() { return 3; }
    static get CHECKBOX_4() { return 4; }
    static get CHECKBOX_5() { return 5; }
    static get CHECKBOX_6() { return 6; }
    static get CHECKBOX_7() { return 7; }
    static get CHECKBOX_8() { return 8; }
    static get CHECKBOX_9() { return 9; }

    get checkbox0() { return this.get(MyCoolCheckboxes.CHECKBOX_0); }
    set checkbox0(value) { return this.set(MyCoolCheckboxes.CHECKBOX_0, value); }

    get checkbox1() { return this.get(MyCoolCheckboxes.CHECKBOX_1); }
    set checkbox1(value) { return this.set(MyCoolCheckboxes.CHECKBOX_1, value); }

    get checkbox2() { return this.get(MyCoolCheckboxes.CHECKBOX_2); }
    set checkbox2(value) { return this.set(MyCoolCheckboxes.CHECKBOX_2, value); }

    get checkbox3() { return this.get(MyCoolCheckboxes.CHECKBOX_3); }
    set checkbox3(value) { return this.set(MyCoolCheckboxes.CHECKBOX_3, value); }

    get checkbox4() { return this.get(MyCoolCheckboxes.CHECKBOX_4); }
    set checkbox4(value) { return this.set(MyCoolCheckboxes.CHECKBOX_4, value); }

    get checkbox5() { return this.get(MyCoolCheckboxes.CHECKBOX_5); }
    set checkbox5(value) { return this.set(MyCoolCheckboxes.CHECKBOX_5, value); }

    get checkbox6() { return this.get(MyCoolCheckboxes.CHECKBOX_6); }
    set checkbox6(value) { return this.set(MyCoolCheckboxes.CHECKBOX_6, value); }

    get checkbox7() { return this.get(MyCoolCheckboxes.CHECKBOX_7); }
    set checkbox7(value) { return this.set(MyCoolCheckboxes.CHECKBOX_7, value); }

    get checkbox8() { return this.get(MyCoolCheckboxes.CHECKBOX_8); }
    set checkbox8(value) { return this.set(MyCoolCheckboxes.CHECKBOX_8, value); }

    get checkbox9() { return this.get(MyCoolCheckboxes.CHECKBOX_9); }
    set checkbox9(value) { return this.set(MyCoolCheckboxes.CHECKBOX_9, value); }
}

var checkboxes = new MyCoolCheckboxes();
checkboxes.checkbox5 = true;
checkboxes.checkbox7 = true;
checkboxes.checkbox8 = true;

console.info(checkboxes.toString());

output: gG

Or with TypeScript:

class MyCoolCheckboxes extends BigBitMask {
    public static readonly CHECKBOX_0 = 0;
    public static readonly CHECKBOX_1 = 1;
    public static readonly CHECKBOX_2 = 2;

    public get checkbox0(): boolean { return this.get(MyCoolCheckboxes.CHECKBOX_0); }
    public set checkbox0(value: boolean) { this.set(MyCoolCheckboxes.CHECKBOX_0, value); }

    public get checkbox1(): boolean { return this.get(MyCoolCheckboxes.CHECKBOX_1); }
    public set checkbox1(value: boolean) { this.set(MyCoolCheckboxes.CHECKBOX_1, value); }

    public get checkbox2(): boolean { return this.get(MyCoolCheckboxes.CHECKBOX_2); }
    public set checkbox2(value: boolean) { this.set(MyCoolCheckboxes.CHECKBOX_2, value); }
}

Useful properties and methods

isEmpty

Returns: boolean

Indicates that the BigBitMask instance has none of its flags set to true.

equals(otherMask)

Returns: boolean

Compares the current BigBitMask instance to another.

or(otherMask)

Returns: void

Assigns to the current instance the result of a bitwise OR operation between the current BigBitMask instance and another.

and(otherMask)

Returns: void

Assigns to the current instance the result of a bitwise AND operation between the current BigBitMask instance and another.

xor(otherMask)

Returns: void

Assigns to the current instance the result of a bitwise XOR operation between the current BigBitMask instance and another.

BigBitMask.EQUALS(maskA, maskB)

Returns: boolean

Compares two BigBitMask instances.

BigBitMask.OR(arg, ...)

Returns: new instance of BigBitMask

Applies a bitwise OR operation between BigBitMask instances and returns the result as a new BigBitMask instance. The arguments are expected to be BigBitMask instances or a single non-empty BigBitMask array.

BigBitMask.AND(arg, ...)

Returns: new instance of BigBitMask

Applies a bitwise AND operation between BigBitMask instances and returns the result as a new BigBitMask instance. The arguments are expected to be BigBitMask instances or a single non-empty BigBitMask array.

BigBitMask.XOR(arg, ...)

Returns: new instance of BigBitMask

Applies a bitwise XOR operation between BigBitMask instances and returns the result as a new BigBitMask instance. The arguments are expected to be BigBitMask instances or a single non-empty BigBitMask array.


License

MIT

Copyright (C) 2020-2022 Aleksej Solomatin