Base64It!

A simple base64 encoder/decoder that works with HTML5 and Node. Supports strict mode and URL safe encoding/decoding.

by Donavon West

HTML

<script src="http://wzrd.in/bundle/consoleit"></script>
<script src="http://wzrd.in/bundle/base64it"></script>

JavaScript

var console = require("consoleit");
var base64 = require("base64it");

var unencoded = "\xff\xef\xfe\xff\xef\xfeTesting 1 2 3"
var display = "Testing 1 2 3 (with a binary suffix)";

function encode(options) {
    var desc = options.urlSafe ? "Url Safe" : "Strict";
    if (options.stripPadding) {
        desc += " (padding stripped)";
    }
    if (options.lineLength) {
        desc += " (line length = " + options.lineLength + ")";
    }
    var encoded = base64.encode(unencoded, options);
    var decoded = base64.decode(encoded);
    var pass = unencoded === decoded;
    var method = pass ? "info" : "error";
    console[method]("%s -> %s", desc, JSON.stringify(encoded));
}

console.info("Welcome to the Base64It! Demo")
console.log("Test string = %s", display);
console.log("");

encode({});
encode({stripPadding:true});
encode({lineLength:5});

console.log("");

encode({urlSafe:true});
encode({urlSafe:true, stripPadding:true});
encode({urlSafe:true, lineLength:5});