# browserify-unibabel

> Base64, TypedArrays, and UTF-8 / Unicode conversions in Browser (and Node) JavaScript

Latest version **3.0.0** (published 2016-12-20) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install browserify-unibabel
pnpm add browserify-unibabel
yarn add browserify-unibabel
bun add browserify-unibabel
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2016-12-20 |
| First published | 2016-12-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | AJ ONeal |
| Maintainers | danfinlay |
| Keywords | ascii, binary, utf8, utf-8, ArrayBuffer, TypedArrays, TypedArray, Uint, Uint8Array, Base64, b64, Base32, b32 |

## Links

- npm: https://www.npmjs.com/package/browserify-unibabel
- Repository: https://github.com/coolaj86/unibabel-js
- Homepage: https://github.com/coolaj86/unibabel-js#readme
- Issues: https://github.com/coolaj86/unibabel-js/issues
- npm.io page: https://npm.io/package/browserify-unibabel

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

- 3.0.0 (latest) — 2016-12-20
- 2.1.3 — 2016-12-20

## README

Unibabel JS: The Browserify-Ready Unibabel
========

A simple browserify style version of Unibabel, exported as a module instead of as a global object.

Currently does not support the add-in support for hex or base32, because I didn't need them when I made this, and its extendable format is a little unusual.  So, PRs welcome.

## Usage

```javascript
var Unibabel = require('unibabel-js')

// Now you can use Unibabel like the original docs below.
```

## Another caveat

The original Unibabel fails hard when loaded into node.js, but this one doesn't. That's because I unit-test some things that include this in a node environment, even when not using it.  I think the hard failure was a little extreme.

To reiterate the error:  You shouldn't use this in node.js, you have Buffers in node.js, and they do this all better.

# Original Unibabel Docs

Minimalistic **Base64**, **TypedArrays**, and **UTF-8** / **Unicode** conversions in Browser (and Node) JavaScript. Optional add-on support for **hex** and **base32**.

See <https://coolaj86.com/articles/base64-unicode-utf-8-javascript-and-you/>

See also

  * [TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encode) / [TextDecoder](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode)
  * [DateView](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
  * [text-encoding](https://github.com/inexorabletash/text-encoding)
  * [TextEncoderLite (based on Buffer)](https://github.com/coolaj86/TextEncoderLite/tree/litest)
  * [TextEncoderLite (based on text-encoding)](https://github.com/coolaj86/TextEncoderLite/tree/lite)
  * [Beatgammit's base64-js](https://github.com/beatgammit/base64-js)

Quick Note to Node.js Users
------------------------

You SHOULD NOT use this module. You already have [`Buffer`](https://nodejs.org/api/buffer.html) and [`thirty-two`](https://github.com/chrisumbel/thirty-two):

```javascript
var buf = new Buffer('I ½ ♥ 💩', 'utf8');
buf.toString('hex');
buf.toString('base64');
buf.toString('ascii');
buf.toString('utf8');
buf.toString('binary'); // deprecated, do not use
```

API
===

```javascript
// TypedArray <--> UTF8
var uint8Array = Unibabel.strToUtf8Arr(str);
var str = Unibabel.utf8ArrToStr(uint8Array);

// TypedArray <--> Base64
var base64 = Unibabel.arrToBase64(uint8Array)
var uint8Array = Unibabel.base64ToArr(base64)
```

**Normal APIs**

`index.js`

* utf8ToBuffer(utf8str) => array
* bufferToUtf8(array) => string
* utf8ToBase64(utf8str) => base64
* base64ToUtf8(base64) => string
* bufferToBase64(array) => base64
* base64ToBuffer(base64) => array

**Hex APIs**

`unibabel.hex.js`

* hexToBuffer(hexstr) => array
* bufferToHex(array) => hexstr

**Base32 APIs**

`unibabel.base32.js`

* base32ToBuffer(b32str) => array
* bufferToBase32(array) => b32str

**Helper APIs**

* utf8ToBinaryString(utf8str) => binstr
* binaryStringToUtf8(binstr) => utf8str
* bufferToBinaryString(buffer) => binstr
* binaryStringToBuffer(binstr) => array

Examples
========

```javascript
// Base64

var myArray = Unibabel.base64ToArr("QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw=="); // "Base 64 \u2014 Mozilla Developer Network"
var myBuffer = Unibabel.base64ToArr("QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw==").buffer; // "Base 64 \u2014 Mozilla Developer Network"

console.log(myBuffer.byteLength);

// Crazy Unicode

var sMyInput = "I'm a ☢ ☃ that plays 𝄢 guitar and spea̧͈͖ks Ar̽̾̈́͒͑ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜!";
var aMyUTF8Input = Unibabel.strToUtf8Arr(sMyInput);
var sMyBase64 = Unibabel.arrToBase64(aMyUTF8Input);

alert(sMyBase64);

var aMyUTF8Output = Unibabel.base64ToArr(sMyBase64);
var sMyOutput = Unibabel.utf8ArrToStr(aMyUTF8Output);

alert(sMyOutput);
```

License
=======

* `index.js` and `unibabel.hex.js` are dual-licensed as Apache 2.0 and MIT.
* `unibabel.base32.js` is a modified version of [thirty-two](https://github.com/chrisumbel/thirty-two) and is therefore licensed MIT.

Some parts of the code were taken from MDN, which Mozilla has licensed in the Public Domain,
which means that I am at liberty to re-license my copy under the Apache 2 and MIT licenses.

See <https://developer.mozilla.org/en-US/docs/MDN/About#Copyrights_and_licenses>

ChangeLog
====

v2.1.0
------

Added `unibabel.base32.js`

v2.0.0
------

The new implementation is binary compatible with node.js, TextEncoder,
and other more-common UTF-8 encodings.

It is also based on DOM APIs which result in much less code and are still
backwards compatible all the way back to IE6 (not on purpose, just that
it happens to work).

See <https://coolaj86.com/articles/base64-unicode-utf-8-javascript-and-you/>

v1.0.0
------

This version was based on the work by good folks at the MDN, however,
the UTF-8 conversion was not byte-compatible with other UTF-8 conversions
(such as node.js and TextEncoder), so don't use it.
See <https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding>

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