# @leichtgewicht/base64-codec

> base64 to/from bytes codec (esm/cjs)

Latest version **1.0.0** (published 2022-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @leichtgewicht/base64-codec
pnpm add @leichtgewicht/base64-codec
yarn add @leichtgewicht/base64-codec
bun add @leichtgewicht/base64-codec
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-05-30 |
| First published | 2022-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Martin Heidegger |
| Maintainers | leichtgewicht |
| Keywords | base64, b64, codec, bytes, encoding, buffer, uint8array |

## Links

- npm: https://www.npmjs.com/package/@leichtgewicht/base64-codec
- Repository: https://github.com/martinheidegger/base64-codec
- Homepage: https://github.com/martinheidegger/base64-codec#readme
- Issues: https://github.com/martinheidegger/base64-codec/issues
- npm.io page: https://npm.io/package/@leichtgewicht/base64-codec

## 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.0.0 (latest) — 2022-05-30

## README

# @leichtgewicht/base64-codec

A javascript-only (esm/cjs) base64 codec that is [abstract-encoding][] compatible,
well-tested and pretty efficient. Bonus: It doesn't use Nodejs' Buffer object
and comes with typescript types.

[abstract-encoding]: https://github.com/mafintosh/abstract-encoding

## Usage

```js
import { base64 } from '@leichtgewicht/base64-codec' // require works too!

const str = 'AA=='
const bytes = base64.encode(
  str,
  new Uint8Array(base64.encodingLength(str)), // own buffer supplied, optional
  0 // offset, at which to write the str, optional
)
str === base64.decode(bytes, 0, bytes.length)
```

## URL Support

Use `base64URL` for de-/encoding for the URL variant of base64.

```js
import { base64URL } from '@leichtgewicht/base64-codec'
```

## Concatenated Buffer

For performance reasons, this codec **does not** support [concatenated
base64 strings](https://en.wikipedia.org/wiki/Base64#Output_padding).

If you need to encode concatenated strings, split them before passing them to this codec.

## Why?

There are plenty of base64 implementations on NPM, but when looking into
them there was none with cjs/esm support that offered positional encoding
and bringing one owns buffer.

## License

[MIT](./LICENSE)

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