+1 and as generic global utility it would be also nice to make it compatible with all strings.
I have this good old object: http://devpro.it/code/214.html 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 + base64.encode(string); }, fromDataURL: function fromDataURL(string) { return base64.decode(string.slice(string.indexOf(base) + base.length)); } } Take care On Sun, May 4, 2014 at 2:16 PM, Mathias Bynens <math...@qiwi.be> 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: http://whatwg.org/html/webappapis.html#atob > > 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@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss