N3RDN/JN/EXT/LIB/base64.min.js

1 line
6.4 KiB
JavaScript
Raw Normal View History

2023-07-12 21:50:31 +08:00
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):function(){var _Base64=global.Base64;var gBase64=factory();gBase64.noConflict=function(){global.Base64=_Base64;return gBase64};if(global.Meteor){Base64=gBase64}global.Base64=gBase64}()})(typeof self!=="undefined"?self:typeof window!=="undefined"?window:typeof global!=="undefined"?global:this,function(){"use strict";var version="3.7.2";var VERSION=version;var _hasatob=typeof atob==="function";var _hasbtoa=typeof btoa==="function";var _hasBuffer=typeof Buffer==="function";var _TD=typeof TextDecoder==="function"?new TextDecoder:undefined;var _TE=typeof TextEncoder==="function"?new TextEncoder:undefined;var b64ch="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var b64chs=Array.prototype.slice.call(b64ch);var b64tab=function(a){var tab={};a.forEach(function(c,i){return tab[c]=i});return tab}(b64chs);var b64re=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;var _fromCC=String.fromCharCode.bind(String);var _U8Afrom=typeof Uint8Array.from==="function"?Uint8Array.from.bind(Uint8Array):function(it,fn){if(fn===void 0){fn=function(x){return x}}return new Uint8Array(Array.prototype.slice.call(it,0).map(fn))};var _mkUriSafe=function(src){return src.replace(/=/g,"").replace(/[+\/]/g,function(m0){return m0=="+"?"-":"_"})};var _tidyB64=function(s){return s.replace(/[^A-Za-z0-9\+\/]/g,"")};var btoaPolyfill=function(bin){var u32,c0,c1,c2,asc="";var pad=bin.length%3;for(var i=0;i<bin.length;){if((c0=bin.charCodeAt(i++))>255||(c1=bin.charCodeAt(i++))>255||(c2=bin.charCodeAt(i++))>255)throw new TypeError("invalid character found");u32=c0<<16|c1<<8|c2;asc+=b64chs[u32>>18&63]+b64chs[u32>>12&63]+b64chs[u32>>6&63]+b64chs[u32&63]}return pad?asc.slice(0,pad-3)+"===".substring(pad):asc};var _btoa=_hasbtoa?function(bin){return btoa(bin)}:_hasBuffer?function(bin){return Buffer.from(bin,"binary").toString("base64")}:btoaPolyfill;var _fromUint8Array=_hasBuffer?function(u8a){return Buffer.from(u8a).toString("base64")}:function(u8a){var maxargs=4096;var strs=[];for(var i=0,l=u8a.length;i<l;i+=maxargs){strs.push(_fromCC.apply(null,u8a.subarray(i,i+maxargs)))}return _btoa(strs.join(""))};var fromUint8Array=function(u8a,urlsafe){if(urlsafe===void 0){urlsafe=false}return urlsafe?_mkUriSafe(_fromUint8Array(u8a)):_fromUint8Array(u8a)};var cb_utob=function(c){if(c.length<2){var cc=c.charCodeAt(0);return cc<128?c:cc<2048?_fromCC(192|cc>>>6)+_fromCC(128|cc&63):_fromCC(224|cc>>>12&15)+_fromCC(128|cc>>>6&63)+_fromCC(128|cc&63)}else{var cc=65536+(c.charCodeAt(0)-55296)*1024+(c.charCodeAt(1)-56320);return _fromCC(240|cc>>>18&7)+_fromCC(128|cc>>>12&63)+_fromCC(128|cc>>>6&63)+_fromCC(128|cc&63)}};var re_utob=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;var utob=function(u){return u.replace(re_utob,cb_utob)};var _encode=_hasBuffer?function(s){return Buffer.from(s,"utf8").toString("base64")}:_TE?function(s){return _fromUint8Array(_TE.encode(s))}:function(s){return _btoa(utob(s))};var encode=function(src,urlsafe){if(urlsafe===void 0){urlsafe=false}return urlsafe?_mkUriSafe(_encode(src)):_encode(src)};var encodeURI=function(src){return encode(src,true)};var re_btou=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;var cb_btou=function(cccc){switch(cccc.length){case 4:var cp=(7&cccc.charCodeAt(0))<<18|(63&cccc.charCodeAt(1))<<12|(63&cccc.charCodeAt(2))<<6|63&cccc.charCodeAt(3),offset=cp-65536;return _fromCC((offset>>>10)+55296)+_fromCC((offset&1023)+56320);case 3:return _fromCC((15&cccc.charCodeAt(0))<<12|(63&cccc.charCodeAt(1))<<6|63&cccc.charCodeAt(2));default:return _fromCC((31&cccc.charCodeAt(0))<<6|63&cccc.charCodeAt(1))}};var btou=function(b){return b.replace(re_btou,cb_btou)};var atobPolyfill=function(asc){asc=asc.replace(/\s+/g,"");if(!b64re.test(asc))throw new TypeError("malformed base64.");asc+="==".slice(2-(asc.length&3));var u24,bin="",r1,r2;for(var i=0;i<asc.length;){u24=b64tab[asc.charAt(i++)]<<18|b64tab[asc.charAt(i++)]<<12|(