# @digitalbazaar/bitstring

> Bitstring module for universal JavaScript

Latest version **3.1.0** (published 2023-01-08) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @digitalbazaar/bitstring
pnpm add @digitalbazaar/bitstring
yarn add @digitalbazaar/bitstring
bun add @digitalbazaar/bitstring
```

## Health

**Score 28/100 (F)** — status: abandoned.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2023-01-08 |
| First published | 2020-07-09 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | separate (@types/digitalbazaar__bitstring) |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 2 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Digital Bazaar, Inc. |
| Maintainers | dlongley, msporny, davidlehn, mattcollier, gannan |
| Keywords | bitstring |

## Links

- npm: https://www.npmjs.com/package/@digitalbazaar/bitstring
- Repository: https://github.com/digitalbazaar/bitstring
- Issues: https://github.com/digitalbazaar/bitstring/issues
- npm.io page: https://npm.io/package/@digitalbazaar/bitstring

## Dependencies (2)

- [pako](https://npm.io/package/pako.md) ^2.0.4
- [base64url-universal](https://npm.io/package/base64url-universal.md) ^2.0.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 3.1.0 (latest) — 2023-01-08
- 3.0.0 — 2023-01-08
- 2.0.0 — 2022-06-02
- 1.2.1 — 2022-01-21
- 1.2.0 — 2020-09-25
- 1.1.0 — 2020-07-10
- 1.0.0 — 2020-07-09

## 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

---
_Source: https://npm.io/package/@digitalbazaar/bitstring · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
