A better btoa and atob that supports non-ASCII characters in a healthy manner.
Compatible with AMD, CommonJS, and ES2015 module loaders.
| ;(function(global){ | |
| const Utoatou = function () {} | |
| var utoa = s => global.btoa(global.unescape(global.encodeURIComponent(s))) | |
| var atou = a => global.decodeURIComponent(global.escape(global.atob(a))) | |
| var utoh = s => btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g,''); | |
| var htou = h => atou(h.replace(/-/g,'+').replace(/_/g,'/')); | |
| Utoatou.utoa = utoa; | |
| Utoatou.atou = atou; | |
| Utoatou.utoh = utoh; | |
| Utoatou.htou = htou; | |
| if (typeof define === 'function' && define.amd) { | |
| define(function(){ return Utoatou }) | |
| } | |
| else if (typeof exports !== 'undefined') { | |
| if (typeof module !== 'undefined' && module.exports) { | |
| exports = module.exports = Utoatou | |
| } | |
| } else { | |
| global.Utoatou = Utoatou | |
| } | |
| }(this)); |