UNPKG

amos-tool

Version:

amos ui tool

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