# @dwbinns/base

> Base64 encodes binary data as text. This library encodes and decodes base64 and base64url. Base64 encodes 6 bits of binary data per character.

Latest version **1.2.1** (published 2024-08-25) · 0 weekly downloads

## Install

```sh
npm install @dwbinns/base
pnpm add @dwbinns/base
yarn add @dwbinns/base
bun add @dwbinns/base
```

## 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.2.1 |
| Published | 2024-08-25 |
| First published | 2023-12-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dwbinns |

## Links

- npm: https://www.npmjs.com/package/@dwbinns/base
- Repository: https://github.com/dwbinns/base
- Homepage: https://github.com/dwbinns/base#readme
- Issues: https://github.com/dwbinns/base/issues
- npm.io page: https://npm.io/package/@dwbinns/base

## Recent versions

- 1.2.1 (latest) — 2024-08-25
- 1.2.0 — 2024-05-28
- 1.1.0 — 2024-05-16
- 1.0.0 — 2023-12-25

## README

# Base64 encoding and decoding
Base64 encodes binary data as text.
This library encodes and decodes base64 and base64url. 
Base64 encodes 6 bits of binary data per character.

```js
import { encode, decode } from "@dwbinns/base/64";
console.log(encode(new Uint8Array([104, 101, 108, 108, 111])));
console.log(encode("hello"));
console.log(decode(encode("hello")));
console.log(new TextDecoder("utf8").decode(decode(encode("hello"))));
```

```
aGVsbG8=
aGVsbG8=
Uint8Array(5) [ 104, 101, 108, 108, 111 ]
hello
```

Base64url is a version of base64 without padding and using only URL-safe characters. See https://datatracker.ietf.org/doc/html/rfc4648

```js
import * as b64url from "@dwbinns/base/64url";
import * as b64 from "@dwbinns/base/64";
console.log(b64url.encode("kM>kM?."));
console.log(b64.encode("kM>kM?."));
```

```
a00-a00_Lg
a00+a00/Lg==
```


Decoded data will be returned as a Uint8Array, and data to be encoded should be supplied as a Uint8Array (a NodeJS Buffer is suitable). 
If a string is supplied to be encoded it will first be converted to an array of bytes using UTF8.

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