var api={};module.exports=api;var _reverseAlphabets={};function _encodeWithByteBuffer(r,e){var t=0,n=e.length,o=e.charAt(0),a=[0];for(t=0;t<r.length();++t){for(var f=0,h=r.at(t);f<a.length;++f)h+=a[f]<<8,a[f]=h%n,h=h/n|0;for(;h>0;)a.push(h%n),h=h/n|0}var i="";for(t=0;0===r.at(t)&&t<r.length()-1;++t)i+=o;for(t=a.length-1;t>=0;--t)i+=e[a[t]];return i}api.encode=function(r,e,t){if("string"!=typeof e)throw TypeError('"alphabet" must be a string.');if(void 0!==t&&"number"!=typeof t)throw TypeError('"maxline" must be a number.');var n="";if(r instanceof Uint8Array){var o=0,a=e.length,f=e.charAt(0),h=[0];for(o=0;o<r.length;++o){for(var i=0,p=r[o];i<h.length;++i)p+=h[i]<<8,h[i]=p%a,p=p/a|0;for(;p>0;)h.push(p%a),p=p/a|0}for(o=0;0===r[o]&&o<r.length-1;++o)n+=f;for(o=h.length-1;o>=0;--o)n+=e[h[o]]}else n=_encodeWithByteBuffer(r,e);if(t){var s=RegExp(".{1,"+t+"}","g");n=n.match(s).join("\r\n")}return n},api.decode=function(r,e){if("string"!=typeof r)throw TypeError('"input" must be a string.');if("string"!=typeof e)throw TypeError('"alphabet" must be a string.');var t=_reverseAlphabets[e];if(!t){t=_reverseAlphabets[e]=[];for(var n=0;n<e.length;++n)t[e.charCodeAt(n)]=n}r=r.replace(/\s/g,"");for(var o=e.length,a=e.charAt(0),f=[0],n=0;n<r.length;n++){var h=t[r.charCodeAt(n)];if(void 0===h)return;for(var i=0,p=h;i<f.length;++i)p+=f[i]*o,f[i]=255&p,p>>=8;for(;p>0;)f.push(255&p),p>>=8}for(var s=0;r[s]===a&&s<r.length-1;++s)f.push(0);return"u">typeof Buffer?Buffer.from(f.reverse()):new Uint8Array(f.reverse())};