UNPKG

owtlab-tracking

Version:
69 lines (68 loc) 2.13 kB
module.exports = { map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', encode(n) { let o = ''; let i = 0; const m = this.map; let i1; let i2; let i3; let e1; let e2; let e3; let e4; n = this.utf8.encode(n); while (i < n.length) { i1 = n.charCodeAt(i++); i2 = n.charCodeAt(i++); i3 = n.charCodeAt(i++); e1 = (i1 >> 2); e2 = (((i1 & 3) << 4) | (i2 >> 4)); e3 = (isNaN(i2) ? 64 : ((i2 & 15) << 2) | (i3 >> 6)); e4 = (isNaN(i2) || isNaN(i3)) ? 64 : i3 & 63; o = o + m.charAt(e1) + m.charAt(e2) + m.charAt(e3) + m.charAt(e4); } return o; }, decode(n) { let o = ''; let i = 0; const m = this.map; const cc = String.fromCharCode; let e1; let e2; let e3; let e4; let c1; let c2; let c3; n = n.replace(/[^A-Za-z0-9\+\/\=]/g, ''); while (i < n.length) { e1 = m.indexOf(n.charAt(i++)); e2 = m.indexOf(n.charAt(i++)); e3 = m.indexOf(n.charAt(i++)); e4 = m.indexOf(n.charAt(i++)); c1 = (e1 << 2) | (e2 >> 4); c2 = ((e2 & 15) << 4) | (e3 >> 2); c3 = ((e3 & 3) << 6) | e4; o = o + (cc(c1) + ((e3 != 64) ? cc(c2) : '')) + (((e4 != 64) ? cc(c3) : '')); } return this.utf8.decode(o); }, utf8: { encode(n) { let o = ''; let i = 0; const cc = String.fromCharCode; let c; while (i < n.length) { c = n.charCodeAt(i++); o += ((c < 128) ? cc(c) : ((c > 127) && (c < 2048)) ? (cc((c >> 6) | 192) + cc((c & 63) | 128)) : (cc((c >> 12) | 224) + cc(((c >> 6) & 63) | 128) + cc((c & 63) | 128))); } return o; }, decode(n) { let o = ''; let i = 0; const cc = String.fromCharCode; let c2; let c; while (i < n.length) { c = n.charCodeAt(i); o += ((c < 128) ? [cc(c), i++][0] : ((c > 191) && (c < 224)) ? [cc(((c & 31) << 6) | ((c2 = n.charCodeAt(i + 1)) & 63)), (i += 2)][0] : [cc(((c & 15) << 12) | (((c2 = n.charCodeAt(i + 1)) & 63) << 6) | ((c3 = n.charCodeAt(i + 2)) & 63)), (i += 3)][0]); } return o; }, }, };