# @hexagon/base64

> Base64 and base64url to string or arraybuffer, and back. Node, Deno or browser.

Latest version **2.0.4** (published 2024-10-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hexagon/base64
pnpm add @hexagon/base64
yarn add @hexagon/base64
bun add @hexagon/base64
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2024-10-18 |
| First published | 2021-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hexagon |
| Maintainers | hexagon |
| Keywords | base64, base64url, parser, isomorphic, arraybuffer, string |

## Links

- npm: https://www.npmjs.com/package/@hexagon/base64
- Repository: https://github.com/hexagon/base64
- Homepage: https://base64.56k.guru
- Issues: https://github.com/hexagon/base64/issues
- npm.io page: https://npm.io/package/@hexagon/base64

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2024-10-18
- 2.0.0-dev.6 (dev) — 2024-10-07
- 2.0.3 — 2024-10-08
- 2.0.2 — 2024-10-08
- 2.0.1 — 2024-10-07
- 2.0.0 — 2024-10-07
- 2.0.0-dev.5 — 2024-10-06
- 2.0.0-dev.4 — 2024-10-06
- 2.0.0-dev.3 — 2024-09-29
- 2.0.0-dev.2 — 2024-09-29
- 2.0.0-dev.1 — 2024-08-14
- 2.0.0-dev.0 — 2024-08-14
- 1.1.28 — 2023-09-18
- 1.1.27 — 2023-08-06
- 1.1.26 — 2023-02-03
- … 18 more at https://npm.io/package/@hexagon/base64/versions

## README

<p align="center">
  <img src="https://cdn.jsdelivr.net/gh/hexagon/base64@main/docs/base64.png" alt="@hexagon/base64" width="200" height="200"><br>
  <br>Probably the only JavaScript base64 library you'll ever need!<br>
</p>

# @hexagon/base64

Encode, decode and validate base64/base64url to string/arraybuffer and vice-versa. Works in Node, Deno and browser.

[![CI](https://github.com/Hexagon/base64/actions/workflows/test.yml/badge.svg)](https://github.com/Hexagon/base64/actions/workflows/test.yml) 
[![npm version](https://badge.fury.io/js/@hexagon%2Fbase64.svg)](https://badge.fury.io/js/@hexagon%2Fbase64) [![NPM Downloads](https://img.shields.io/npm/dm/@hexagon/base64.svg)](https://www.npmjs.org/package/@hexagon/base64) [![jsdelivr](https://data.jsdelivr.com/v1/package/npm/@hexagon/base64/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@hexagon/base64) 
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Hexagon/base64/blob/master/LICENSE) 

*   Supports regular base64 and base64url
*   Convert to/from string or arraybuffer
*   Validate / identify base64 and base64url
*   Works in Node.js >=4.0 (both require and import).
*   Works in Deno >=1.16.
*   Works in browsers as standalone, UMD or ES-module.
*   Includes [TypeScript](https://www.typescriptlang.org/) typings.


```javascript
// Encode string as regular base64
const example1enc = base64.fromString("Hellö Wörld, how are you doing today?!");
console.log(example1enc);
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==

// Decode string as regular base64
const example1dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==");
console.log(example1dec);
// > Hellö Wörld, how are you doing today?!
```

Full documentation available at [base64.56k.guru](https://base64.56k.guru)

## Quick Installation

**Node.js:**

```bash
npm install @hexagon/base64 --save
```

**Deno (x):**
```js
import { base64 } from "https://deno.land/x/b64@2.0.3/src/base64.ts";
```

**Deno (jsr.io):**
```js
import { base64 } from "jsr:@hexagon/base64";
```

For browser/cdn usage, refer to the documentation.

### Quick API

 - __fromArrayBuffer(buffer, urlMode)__ - Encodes `ArrayBuffer` into base64 or base64url if urlMode(optional) is true
 - __toArrayBuffer(str, urlMode)__ - Decodes base64url string (or base64url string if urlMode is true) to `ArrayBuffer`

 - __fromString(str, urlMode)__ - Encodes `String` into base64 string(base64url string if urlMode is true)
 - __toString(str, urlMode)__ - Decodes base64 or base64url string to `String`

- __validate(str, urlMode)__ - Returns true if `String` str is valid base64/base64 dependending on urlMode

## Contributing

See [Contribution Guide](https://base64.56k.guru/contributing.html)

## Donations

If you found this library helpful and wish to support its development, consider making a donation through [Hexagon's GitHub Sponsors page](https://github.com/sponsors/hexagon). Your generosity ensures the library's continued development and maintenance.

### Contributors

The underlying code is loosely based on [github.com/niklasvh/base64-arraybuffer](https://github.com/niklasvh/base64-arraybuffer)

## License

MIT

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