Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lionralfs/boolopt
A tiny package to get and set boolean options using bitwise operations
https://github.com/lionralfs/boolopt
Last synced: 3 days ago
JSON representation
A tiny package to get and set boolean options using bitwise operations
- Host: GitHub
- URL: https://github.com/lionralfs/boolopt
- Owner: lionralfs
- License: mit
- Created: 2019-11-30T22:16:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-02T02:25:18.000Z (9 months ago)
- Last Synced: 2024-10-23T09:13:13.142Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 771 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# boolopt (boolean options)
A tiny package to get and set boolean options using bitwise operations.
## Installation
```bash
npm install --save boolopt
```## Usage
Calling boolopt returns an object with the methods `get` and `set` on it.
```js
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); // trueset(1, true);
get(1); // true
```It combines nicely with enums:
```js
const OPTIONS = Object.freeze({ HUNGRY: 0, TIRED: 1 });const { get, set } = boolopt();
set(OPTIONS.HUNGRY, true);
set(OPTIONS.TIRED, true);
```## License
[MIT](LICENSE) © Lion Ralfs