diff options
Diffstat (limited to 'public/baseex.js')
-rw-r--r-- | public/baseex.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/public/baseex.js b/public/baseex.js new file mode 100644 index 0000000..5a0fb06 --- /dev/null +++ b/public/baseex.js @@ -0,0 +1,8 @@ +var BaseEx=function(t){"use strict"; + /* + * [BaseEx]{@link https://github.com/UmamiAppearance/BaseExJS} + * + * @version 0.3.3 + * @author UmamiAppearance [mail@umamiappearance.eu] + * @license GPL-3.0 AND BSD-3-Clause (Base91, Copyright (c) 2000-2006 Joachim Henke) + */class e{constructor(t="default",e="str",s="str"){this.charsets={default:"0123456789abcdef"},this.IOtypes=["str","bytes"],this.utils=new a(this),[this.version,this.defaultInput,this.defaultOutput]=this.utils.validateArgs([t,e,s]),this.converter=new o(16,1,2),this.converter.padAmount=[0]}encode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.setIOType(e,"in"),i=this.utils.getVersion(e);t=this.utils.validateInput(t,s);const r="str"===s?(new TextEncoder).encode(t):t;return this.converter.encode(r,this.charsets[i])[0]}decode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.getVersion(e),i=this.utils.setIOType(e,"out");(t=(t=String(t).replace(/^0x/,"")).toLowerCase()).length%2&&(t="0".concat(t));const r=this.converter.decode(t,this.charsets[s]);return"bytes"===i?r:(new TextDecoder).decode(r)}}class s{constructor(t="rfc4648",e="str",s="str",i=!0){this.charsets={rfc3548:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",rfc4648:"0123456789ABCDEFGHIJKLMNOPQRSTUV"},this.padding=Boolean(i),this.IOtypes=["str","bytes"],this.utils=new a(this),[this.version,this.defaultInput,this.defaultOutput]=this.utils.validateArgs([t,e,s]),this.converter=new o(32,5,8),this.converter.padAmount=[0,1,3,4,6]}encode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.setIOType(e,"in"),i=this.utils.getVersion(e);t=this.utils.validateInput(t,s);const r="str"===s?(new TextEncoder).encode(t):t;let n,o;if([n,o]=this.converter.encode(r,this.charsets[i]),o){const t=this.converter.padAmount[o];n=n.slice(0,n.length-t),this.padding&&(n=n.concat("=".repeat(t)))}return n}decode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.getVersion(e),i=this.utils.setIOType(e,"out"),r=(t=t.toUpperCase()).length%8;r&&(t=t.padEnd(t.length+8-r,"="));const n=this.converter.decode(t,this.charsets[s]);return"bytes"===i?n:(new TextDecoder).decode(n)}}class i{constructor(t="default",e="str",s="str",i=!0){const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";this.charsets={default:r.concat("+/"),urlsafe:r.concat("-_")},this.padding=Boolean(i),this.IOtypes=["str","bytes"],this.utils=new a(this),[this.version,this.defaultInput,this.defaultOutput]=this.utils.validateArgs([t,e,s]),this.converter=new o(64,3,4),this.converter.padAmount=[0,1,2]}encode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.setIOType(e,"in"),i=this.utils.getVersion(e);t=this.utils.validateInput(t,s);const r="str"===s?(new TextEncoder).encode(t):t;let n,o;if([n,o]=this.converter.encode(r,this.charsets[i]),o){const t=this.converter.padAmount[o];n=n.slice(0,n.length-t),this.padding&&(n=n.concat("=".repeat(t)))}return n}decode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.getVersion(e),i=this.utils.setIOType(e,"out"),r=t.length%4;r&&(t=t.padEnd(t.length+4-r,"="));const n=this.converter.decode(t,this.charsets[s]);return"bytes"===i?n:(new TextDecoder).decode(n)}}class r{constructor(t="ascii85",e="str",s="str",i=!1){const r="!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu";this.charsets={ascii85:r,adobe:r,rfc1924:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~",z85:"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"},this.IOtypes=["str","bytes"],this.utils=new a(this),this.expandUtils(i),[this.version,this.defaultInput,this.defaultOutput]=this.utils.validateArgs([t,e,s]),this.converter=new o(85,4,5),this.converter.padAmount=[0]}encode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.setIOType(e,"in"),i=this.utils.getVersion(e);t=this.utils.validateInput(t,s);const r="str"===s?(new TextEncoder).encode(t):t;let n,o,a=null;return i.match(/adobe|ascii85/)&&(a=(t,e)=>e||"!!!!!"!==t?t:"z"),[n,o]=this.converter.encode(r,this.charsets[i],a),n=n.slice(0,n.length-o),"adobe"===i&&(n=`<~${n}~>`),"rfc1924"===i&&this.utils.announce(),n}decode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.getVersion(e),i=this.utils.setIOType(e,"out");t=t.replace(/\s/g,""),s.match(/adobe|ascii85/)&&(t=t.replace(/z/g,"!!!!!"),"adobe"===s&&(t=t.replace(/^<~|~>$/g,"")));const r=this.converter.decode(t,this.charsets[s]);return"bytes"===i?r:(new TextDecoder).decode(r)}expandUtils(t){this.utils.announce=()=>{if(!t){const t=new Date;if(3===t.getMonth()&&1===t.getDate())console.log(" __\n _(\\ |@@|\n(__/\\__ \\--/ __\n \\___|----| | __\n \\ }{ /\\ )_ / _\\\n /\\__/\\ \\__O (__\n (--/--) \\__/\n _)( )(_\n `---''---`");else{const e=t.getTime();t.setMonth(3,1),t.setHours(0,0,0),t.getTime()<e&&t.setFullYear(t.getFullYear()+1);const s=t-e,i=`Time left: ${Math.floor(s/864e5)} days, ${Math.floor(s%864e5/36e5)} hours, ${Math.floor(s%36e5/6e4)} minutes`;this.utils.warning("Only the charset is used. The input is not taken as a 128 bit integer. (because this is madness)"),this.utils.warning(i)}}}}}class n{constructor(t="default",e="str",s="str"){this.charsets={default:'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"'},this.IOtypes=["str","bytes"],this.utils=new a(this),this.utils.binPow={13:8192,14:16384},this.utils.divmod=(t,e)=>[Math.floor(t/e),t%e],[this.version,this.defaultInput,this.defaultOutput]=this.utils.validateArgs([t,e,s])}encode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.setIOType(e,"in"),i=this.utils.getVersion(e);t=this.utils.validateInput(t,s);const r="str"===s?(new TextEncoder).encode(t):t;let n=0,o=0,a="";const h=this.charsets[i];if(r.forEach((t=>{if(o+=t<<n,n+=8,n>13){let t,e,s=13,i=o%this.utils.binPow[13];i<89&&(s=14,i=o%this.utils.binPow[14]),o>>=s,n-=s,[t,e]=this.utils.divmod(i,91),a=`${a}${h[e]}${h[t]}`}})),n){let t,e;[t,e]=this.utils.divmod(o,91),a=a.concat(h[e]),(n>7||o>90)&&(a=a.concat(h[t]))}return a}decode(t,...e){e=this.utils.validateArgs(e);const s=this.utils.getVersion(e),i=this.utils.setIOType(e,"out");let r=(t=t.replace(/\s/g,"")).length,n=!1;r%2&&(n=!0,r--);let o=0,a=0;const h=this.charsets[s],c=new Array;for(let e=0;e<r;e+=2){const s=h.indexOf(t[e])+91*h.indexOf(t[e+1]);o=(s<<a)+o,a+=s%this.utils.binPow[13]>88?13:14;do{c.push(o%256),o>>=8,a-=8}while(a>7)}if(n){const e=t.charAt(r),s=h.indexOf(e);c.push(((s<<a)+o)%256)}const l=Uint8Array.from(c);return"bytes"===i?l:(new TextDecoder).decode(l)}}class o{constructor(t,e,s){this.radix=t,this.bsEnc=e,this.bsDec=s}encode(t,e,s=null){let i="",r=0;const n=this.bsEnc;if(n>6)throw new RangeError("The given blocksize may require big integers (> 2^53) during conversion.\nThis is not supported.");for(let o=0,a=t.length;o<a;o+=n){let a=t.slice(o,o+n);if(a.length<n){r=n-a.length;const t=new Uint8Array(n);t.set(a),a=t}let h=0;a.forEach(((t,e)=>h+=t*this.pow(256,n-1-e)));const c=new Array;let l,u=h;for(;u>=this.radix;)[u,l]=this.divmod(u,this.radix),c.unshift(l);for(c.unshift(u);c.length<this.bsDec;)c.unshift(0);let d="";c.forEach((t=>d=d.concat(e[t]))),s&&(d=s(d,r)),i=i.concat(d)}return[i,r]}decode(t,e){const s=this.bsDec;let i=0;const r=Uint8Array.from(t.split("").map((t=>{const s=e.indexOf(t);return s<0?(i++,0):s})));let n=this.padAmount.indexOf(i),o=new Array;for(let e=0,i=t.length;e<i;e+=s){let t=r.slice(e,e+s);if(t.length<s){n=s-t.length;const e=Uint8Array.from(Array(s).fill(this.radix-1));e.set(t),t=e}const i=new Array;let a=0;t.forEach(((t,e)=>a+=t*this.pow(this.radix,s-1-e)));let h,c=a;for(;c>=256;)[c,h]=this.divmod(c,256),i.unshift(h);for(i.unshift(c);i.length<this.bsEnc;)i.unshift(0);o=o.concat(i)}return Uint8Array.from(o.slice(0,o.length-n))}divmod(t,e){return[Math.floor(t/e),t%e]}pow(t,e){return{16:[1,16],32:[1,32,1024,32768,32**4,32**5,32**6,32**7],64:[1,64,4096,64**3],85:[1,85,7225,85**3,85**4],256:[1,256,65536,256**3,256**4]}[t][e]}}class a{constructor(t){this.root=t,"charsets"in t&&this.charsetUserToolsConstructor()}charsetUserToolsConstructor(){this.root.addCharset=(t,e)=>{if("string"!=typeof t)throw new TypeError("The charset name must be a string.");const s=this.root.converter.radix;let i=s;if("string"==typeof e||Array.isArray(e))i=e.length,e=new Set(e);else if(!(e instanceof Set))throw new TypeError("The charset must be one of the types:\n'str', 'set', 'array'.");if(e.size!==s)throw i===s?new Error("There were repetitive chars found in your charset. Make sure each char is unique."):new Error(`The the length of the charset must be ${s}.`);e=[...e].join(""),this.root.charsets[t]=e,console.log(`New charset added with the name '${t}' added and ready to use`)},this.root.setDefaultVersion=t=>[this.root.version]=this.validateArgs([t])}makeArgList(t){return t.map((t=>`'${t}'`)).join(", ")}setIOType(t,e){let s;return s=t.includes("bytes")?"bytes":t.includes("str")?"str":"in"===e?this.root.defaultInput:this.root.defaultOutput,s}getVersion(t){let e=this.root.version;return t.forEach((t=>{t in this.root.charsets&&(e=t)})),e}validateArgs(t){let e,s=null;const i=new Array;return"charsets"in this.root?(s=Object.keys(this.root.charsets),e=[...this.root.IOtypes,...s]):e=this.root.IOtypes,t.length&&t.forEach((t=>{if(t=String(t).toLowerCase(),!e.includes(t)){const e=s?`The options for version (charset) are:\n${this.makeArgList(s)}\n\n`:"";throw new TypeError(`'${t}'\n\nValid arguments for in- and output-type are:\n${this.makeArgList(this.root.IOtypes)}\n\n${e}Traceback:`)}i.push(t)})),i}validateInput(t,e){if("str"===e)return"string"!=typeof t&&this.warning("Your input was converted into a string."),String(t);if("string"==typeof t)throw new TypeError("Your provided input is a string, but some kind of (typed) Array is expected.");if(!ArrayBuffer.isView(t)&&!Array.isArray(t))throw new TypeError("Input must be some kind of (typed) Array if input type is set to 'bytes'.");return t}warning(t){Object.prototype.hasOwnProperty.call(console,"warn")?console.warn(t):console.log(`___\n${t}\n`)}}return t.Base16=e,t.Base32=s,t.Base64=i,t.Base85=r,t.Base91=n,t.BaseEx=class{constructor(t="str",o="str"){this.base16=new e("default",t,o),this.base32_rfc3548=new s("rfc3548",t,o),this.base32_rfc4648=new s("rfc4648",t,o),this.base64=new i("default",t,o),this.base64_urlsafe=new i("urlsafe",t,o),this.base85adobe=new r("adobe",t,o),this.base85ascii=new r("ascii85",t,o),this.base85_z85=new r("z85",t,o),this.base91=new n("default",t,o)}},Object.defineProperty(t,"__esModule",{value:!0}),t}({});
\ No newline at end of file |