- TextEncoder / TextDecoder
- TextEncoderLite (based on Buffer)
- TextEncoderLite (based on text-encoding)
- Beatgammit's base64-js
Are you in the right place?
Dear Node.js Users:
var buf = 'I ½ ♥ 💩' 'utf8';buf;buf;buf;buf;buf; // deprecated, do not use
You just include the
index.js in a lovely script tag.
bower install --save unibabel
Dear WebPack / Broccoli, Gulp / Grunt Users:
I don't know how your build systems work these days,
but Unibabel is exported as
and you can access it as
// TypedArray <--> UTF8var uint8Array = Unibabel;var str = Unibabel;// TypedArray <--> Base64var base64 = Unibabelvar uint8Array = Unibabel
- utf8ToBuffer(utf8str) => array
- bufferToUtf8(array) => string
- utf8ToBase64(utf8str) => base64
- base64ToUtf8(base64) => string
- bufferToBase64(array) => base64
- base64ToBuffer(base64) => array
- hexToBuffer(hexstr) => array
- bufferToHex(array) => hexstr
- base32ToBuffer(b32str) => array
- bufferToBase32(array) => b32str
- utf8ToBinaryString(utf8str) => binstr
- binaryStringToUtf8(binstr) => utf8str
- bufferToBinaryString(buffer) => binstr
- binaryStringToBuffer(binstr) => array
// Base64var myArray = Unibabel; // "Base 64 \u2014 Mozilla Developer Network"var myBuffer = Unibabelbuffer; // "Base 64 \u2014 Mozilla Developer Network"console;// Crazy Unicodevar sMyInput = "I'm a ☢ ☃ that plays 𝄢 guitar and spea̧͈͖ks Ar̽̾̈́͒͑ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜!";var aMyUTF8Input = Unibabel;var sMyBase64 = Unibabel;;var aMyUTF8Output = Unibabel;var sMyOutput = Unibabel;;
unibabel.hex.jsare dual-licensed as Apache 2.0 and MIT.
unibabel.base32.jsis a modified version of 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.
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).
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