# str2buf

> isomorphic string buffer in 198 bytes

Latest version **1.3.0** (published 2018-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install str2buf
pnpm add str2buf
yarn add str2buf
bun add str2buf
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2018-02-08 |
| First published | 2018-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | kevlened |
| Keywords | string, buffer |

## Links

- npm: https://www.npmjs.com/package/str2buf
- Repository: https://github.com/kevlened/str2buf
- Homepage: https://github.com/kevlened/str2buf#readme
- Issues: https://github.com/kevlened/str2buf/issues
- npm.io page: https://npm.io/package/str2buf

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2018-02-08
- 1.2.2 — 2018-01-24
- 1.2.1 — 2018-01-24
- 1.2.0 — 2018-01-08
- 1.1.1 — 2018-01-07
- 1.1.0 — 2018-01-07
- 1.0.0 — 2018-01-06

## README

# str2buf [![NPM](https://img.shields.io/npm/v/str2buf.svg)](https://npmjs.com/package/str2buf) [![Build](https://travis-ci.org/kevlened/str2buf.svg?branch=master)](https://travis-ci.org/kevlened/str2buf)
isomorphic string <=> buffer in 198 bytes

## Install

`npm install str2buf`

## Usage

You must provide strings where each character is represented by a single byte (also known as the binary string format). For example, the output of a `atob` operation or any ASCII string would be allowed.

```javascript
const str2buf = require('str2buf')

str2buf.toUint8Array('hello')
// new Uint8Array([104,101,108,108,111])

str2buf.fromUint8Array(new Uint8Array([104,101,108,108,111]))
// 'hello'

str2buf.toBuffer('hello')
// ArrayBuffer

str2buf.fromBuffer(new Uint8Array([104,101,108,108,111]).buffer)
// 'hello'
```

## Can it be smaller?

If you use ES6 imports with a bundler that supports tree-shaking, yes!

```javascript
import { fromUint8Array } from 'str2buf'
```

#### Perf profile

```
⏱ browser performance on 1000 arrays or strings of size 25003:
str2buf.fromUint8Array: 245.842ms
str2buf.toUint8Array: 165.240ms
str2buf.fromBuffer: 234.920ms
str2buf.toBuffer: 160.021ms

⏱ node performance on 1000 arrays or strings of size 25003:
str2buf.fromUint8Array: 20.213ms
str2buf.toUint8Array: 15.655ms
str2buf.fromBuffer: 32.880ms
str2buf.toBuffer: 21.514ms
```

## License

MIT

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