https://github.com/digitalbazaar/bitstring
A Bitstring module for universal JavaScript
https://github.com/digitalbazaar/bitstring
Last synced: about 1 year ago
JSON representation
A Bitstring module for universal JavaScript
- Host: GitHub
- URL: https://github.com/digitalbazaar/bitstring
- Owner: digitalbazaar
- License: bsd-3-clause
- Created: 2020-07-07T17:45:48.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T21:33:58.000Z (over 3 years ago)
- Last Synced: 2025-04-15T04:39:12.777Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 3
- Watchers: 12
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Bitstring
A Bitstring module for universal JavaScript.
## Install
To install get the latest version from NPM:
```
npm install @digitalbazaar/bitstring
```
To install locally for development:
```
git clone https://github.com/digitalbazaar/bitstring.git
cd bitstring
npm install
```
## Usage
```js
import {Bitstring} from '@digitalbazaar/bitstring';
// You can make a new instance by passing in a length
const bitstring = new Bitstring({length: 10});
// OR by passing in a buffer
const buffer = Uint8Array.from([255]);
const bitstring = new Bitstring({buffer});
```
## API
### set(position, on)
Sets the value of a bit for the given position to the given boolean.
```js
bitstring.set(1, true);
```
### get(position)
Gets the value of a bit for the given position.
```js
bitstring.get(3);
```
### encodeBits()
Compresses and encodes bits to a base64url encoded string.
```js
await bitstring.encodeBits();
```
### decodeBits({encoded})
Decodes and uncompresses a given base64url encoded string to a Uint8Array.
```js
await Bitstring.decodeBits({encoded});
```
### compressBits()
Compresses bits to a Uint8Array.
```js
await bitstring.compressBits();
```
### uncompressBits({compressed})
Uncompresses compressed bits.
```js
await Bitstring.uncompressBits({compressed});
```
## Contribute
Please follow the existing code style.
PRs accepted.
If editing the Readme, please conform to the
[standard-readme](https://github.com/RichardLitt/standard-readme) specification.
## Commercial Support
Commercial support for this library is available upon request from
Digital Bazaar: support@digitalbazaar.com
## License
[BSD-3-Clause](LICENSE.md) © Digital Bazaar