boolopt
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

boolopt (boolean options)

A tiny package to get and set boolean options using bitwise operations.

Installation

npm install --save boolopt

Usage

Calling boolopt returns an object with the methods get and set on it.

import boolopt from 'boolopt';

// initialize the values (omitting them sets them to 0)
const { get, set } = boolopt(false, false, true);

// you can now access them by index
get(0); // false
get(1); // false
get(2); // true

set(1, true);

get(1); // true

It combines nicely with enums:

const OPTIONS = Object.freeze({ HUNGRY: 0, TIRED: 1 });

const { get, set } = boolopt();

set(OPTIONS.HUNGRY, true);
set(OPTIONS.TIRED, true);

License

MIT © Lion Ralfs

Readme

Keywords

none

Package Sidebar

Install

npm i boolopt

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.11 kB

Total Files

13

Last publish

Collaborators

  • lionralfs