npm install base-64
In a browser:
var base64 = ;
Using an AMD loader like RequireJS:
A string representing the semantic version number.
This function takes a byte string (the
input parameter) and encodes it according to base64. The input data must be in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values
base64.encode() function is designed to be fully compatible with
btoa() as described in the HTML Standard.
var encodedData = base64;
To base64-encode any Unicode string, encode it as UTF-8 first:
var base64 = ;var utf8 = ;var text = 'foo © bar 𝌆 baz';var bytes = utf8;var encoded = base64;console;// → 'Zm9vIMKpIGJhciDwnYyGIGJheg=='
This function takes a base64-encoded string (the
input parameter) and decodes it. The return value is in the form of a string containing only characters in the range from U+0000 to U+00FF, each representing a binary byte with values
base64.decode() function is designed to be fully compatible with
atob() as described in the HTML Standard.
var decodedData = base64;
To base64-decode UTF-8-encoded data back into a Unicode string, UTF-8-decode it after base64-decoding it:
var encoded = 'Zm9vIMKpIGJhciDwnYyGIGJheg==';var bytes = base64;var text = utf8;console;// → 'foo © bar 𝌆 baz'
base64 is designed to work in at least Node.js v0.10.0, Narwhal 0.3.2, RingoJS 0.8-0.9, PhantomJS 1.9.0, Rhino 1.7RC4, as well as old and modern versions of Chrome, Firefox, Safari, Opera, and Internet Explorer.
Unit tests & code coverage
After cloning this repository, run
npm install to install the dependencies needed for development and testing. You may want to install Istanbul globally using
npm install istanbul -g.
Once that’s done, you can run the unit tests in Node using
npm test or
node tests/tests.js. To run the tests in Rhino, Ringo, Narwhal, and web browsers as well, use
To generate the code coverage report, use
base64 is available under the MIT license.