UNPKG

@fast-china/utils

Version:

Fast 工具库.

3 lines (2 loc) 2.77 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",e=/^(?:[A-Z\d+/]{4})*?(?:[A-Z\d+/]{2}(?:==)?|[A-Z\d+/]{3}=?)?$/i,d=[{index:977,randomIndex:188},{index:926,randomIndex:201},{index:851,randomIndex:225},{index:700,randomIndex:255},{index:600,randomIndex:268},{index:500,randomIndex:277},{index:400,randomIndex:288},{index:330,randomIndex:327},{index:300,randomIndex:180},{index:200,randomIndex:178},{index:100,randomIndex:124},{index:98,randomIndex:95},{index:92,randomIndex:90},{index:91,randomIndex:87},{index:88,randomIndex:84},{index:82,randomIndex:79},{index:78,randomIndex:71},{index:72,randomIndex:69},{index:68,randomIndex:66},{index:59,randomIndex:55},{index:48,randomIndex:43},{index:42,randomIndex:37},{index:36,randomIndex:30},{index:33,randomIndex:27},{index:24,randomIndex:20},{index:23,randomIndex:18},{index:21,randomIndex:16},{index:17,randomIndex:14},{index:13,randomIndex:9},{index:7,randomIndex:4},{index:5,randomIndex:3},{index:2,randomIndex:1}];const r={bota(e){let d,r,o,t,i="",x=0,a=(e=String(e)).length%3;for(;x<e.length;){if((r=e.charCodeAt(x++))>255||(o=e.charCodeAt(x++))>255||(t=e.charCodeAt(x++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");d=r<<16|o<<8|t,i+=n.charAt(d>>18&63)+n.charAt(d>>12&63)+n.charAt(d>>6&63)+n.charAt(63&d)}return a?i.slice(0,a-3)+"===".substring(a):i},atob(d){if(d=String(d).replace(/[\t\n\f\r ]+/g,""),!e.test(d))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");d+="==".slice(2-(3&d.length));let r,o,t,i="",x=0;for(;x<d.length;)r=n.indexOf(d.charAt(x++))<<18|n.indexOf(d.charAt(x++))<<12|(o=n.indexOf(d.charAt(x++)))<<6|(t=n.indexOf(d.charAt(x++))),i+=64===o?String.fromCharCode(r>>16&255):64===t?String.fromCharCode(r>>16&255,r>>8&255):String.fromCharCode(r>>16&255,r>>8&255,255&r);return i},toBase64(n,e=6){if(0===n.length)return"";const o=function(n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",e=6){let d="";for(let r=0;r<e;r++)d+=n[Math.ceil(Math.random()*(n.length-1))];return d}();let t=r.bota(encodeURIComponent(n));return 0!==e&&(t=function(n){let e=n;return d.sort(((n,e)=>e.index-n.index)).forEach((d=>{if(d.index<n.length){const r=n[d.randomIndex];e=e.slice(0,d.index)+r+e.slice(d.index)}})),e}(t)),o+t},base64ToStr(n,e=6){let o=n;if(0===n.length)return"";let t=n.slice(e);return 0!==e&&(t=function(n){const e=d.sort(((n,e)=>n.index-e.index));let r=n;return e.forEach((e=>{e.index<n.length&&(r=r.slice(0,e.index)+r.slice(e.index+1))})),r}(t)),o=r.atob(t),decodeURIComponent(o)}};exports.base64Util=r; //# sourceMappingURL=index.js.map