UNPKG

amos-tool

Version:

amos ui tool

27 lines (26 loc) 1.9 kB
var Base64 = function() { var r = this, e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; this.encode = function(t) { var o, a, n, h, d, C, c, f = "", i = 0; for (t = r._utf8_encode(t); i < t.length;) o = t.charCodeAt(i++), a = t.charCodeAt(i++), n = t.charCodeAt(i++), h = o >> 2, d = (3 & o) << 4 | a >> 4, C = (15 & a) << 2 | n >> 6, c = 63 & n, isNaN(a) ? C = c = 64 : isNaN(n) && (c = 64), f = f + e.charAt(h) + e.charAt(d) + e.charAt(C) + e.charAt(c); return f }, this.decode = function(t) { var o, a, n, h, d, C, c, f = "", i = 0; for (t = t.replace(/[^A-Za-z0-9\+\/\=]/g, ""); i < t.length;) h = e.indexOf(t.charAt(i++)), d = e.indexOf(t.charAt(i++)), C = e.indexOf(t.charAt(i++)), c = e.indexOf(t.charAt(i++)), o = h << 2 | d >> 4, a = (15 & d) << 4 | C >> 2, n = (3 & C) << 6 | c, f += String.fromCharCode(o), 64 != C && (f += String.fromCharCode(a)), 64 != c && (f += String.fromCharCode(n)); return f = r._utf8_decode(f) }, this._utf8_encode = function(r) { r = r.replace(/\r\n/g, "\n"); for (var e = "", t = 0; t < r.length; t++) { var o = r.charCodeAt(t); o < 128 ? e += String.fromCharCode(o) : o > 127 && o < 2048 ? (e += String.fromCharCode(o >> 6 | 192), e += String.fromCharCode(63 & o | 128)) : (e += String.fromCharCode(o >> 12 | 224), e += String.fromCharCode(o >> 6 & 63 | 128), e += String.fromCharCode(63 & o | 128)) } return e }, this._utf8_decode = function(r) { for (var e = "", t = 0, o = 0, a = 0, n = 0; t < r.length;) o = r.charCodeAt(t), o < 128 ? (e += String.fromCharCode(o), t++) : o > 191 && o < 224 ? (a = r.charCodeAt(t + 1), e += String.fromCharCode((31 & o) << 6 | 63 & a), t += 2) : (a = r.charCodeAt(t + 1), n = r.charCodeAt(t + 2), e += String.fromCharCode((15 & o) << 12 | (63 & a) << 6 | 63 & n), t += 3); return e } }; module.exports = Base64;