Native base64 utility methods

Andrea Giammarchi andrea.giammarchi at
Sun May 4 15:00:04 PDT 2014

+1 and as generic global utility it would be also nice to make it
compatible with all strings.

I have this good old object:

that indeed needs to normalize before encoding or decoding or errors might
happen quite frequently in user-land:

        atob: atob,
        btoa: btoa,
        fromCharCode: fromCharCode,
        encode: function encode(string) {
            return btoa(unescape(encodeURIComponent(string)));
        decode: function decode(string) {
            return decodeURIComponent(escape(atob(string)));
        toDataURL: function toDataURL(string, mime) {
            return "data:" + (mime ? mime + ";" : "") + base +
        fromDataURL: function fromDataURL(string) {
            return base64.decode(string.slice(string.indexOf(base) +

Take care

On Sun, May 4, 2014 at 2:16 PM, Mathias Bynens <mathias at> wrote:

> To convert from base64 to ASCII and vice versa, browsers have had global
> `atob` and `btoa` functions for a while now. At the moment, these are
> defined in the HTML standard:
> However, such utility methods are not only useful in browsers. How about
> adding these as global functions to ECMAScript so that they’re natively
> available in all JavaScript engines, not just in browser environments?
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list