boolopt
v1.0.0
Published
A tiny package to get and set boolean options using bitwise operations.
Downloads
2
Readme
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