4 lines
18 KiB
JavaScript
4 lines
18 KiB
JavaScript
|
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Uint8Arrays = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
||
|
|
"use strict";var Uint8Arrays=(()=>{var X=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var r in e)X(t,r,{get:e[r],enumerable:!0})},Xe=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Re(e))!Je.call(t,n)&&n!==r&&X(t,n,{get:()=>e[n],enumerable:!(o=je(e,n))||o.enumerable});return t};var Qe=t=>Xe(X({},"__esModule",{value:!0}),t);var tr={};d(tr,{compare:()=>le,concat:()=>me,equals:()=>be,fromString:()=>$e,toString:()=>Fe,xor:()=>ke});function le(t,e){if(globalThis.Buffer!=null)return globalThis.Buffer.compare(t,e);for(let r=0;r<t.byteLength;r++){if(t[r]<e[r])return-1;if(t[r]>e[r])return 1}return t.byteLength>e.byteLength?1:t.byteLength<e.byteLength?-1:0}function S(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function I(t=0){return globalThis.Buffer?.allocUnsafe!=null?S(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function me(t,e){e==null&&(e=t.reduce((n,s)=>n+s.length,0));let r=I(e),o=0;for(let n of t)r.set(n,o),o+=n.length;return S(r)}function be(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var W={};d(W,{base10:()=>Ye});function Ge(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=n}var c=t.length,h=t.charAt(0),T=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function B(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var p=0,E=0,m=0,x=a.length;m!==x&&a[m]===0;)m++,p++;for(var g=(x-m)*u+1>>>0,l=new Uint8Array(g);m!==x;){for(var w=a[m],C=0,b=g-1;(w!==0||C<E)&&b!==-1;b--,C++)w+=256*l[b]>>>0,l[b]=w%c>>>0,w=w/c>>>0;if(w!==0)throw new Error("Non-zero carry");E=C,m++}for(var v=g-E;v!==g&&l[v]===0;)v++;for(var q=h.repeat(p);v<g;++v)q+=t.charAt(l[v]);return q}function k(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var p=0;if(a[p]!==" "){for(var E=0,m=0;a[p]===h;)E++,p++;for(var x=(a.length-p)*T+1>>>0,g=new Uint8Array(x);a[p];){var l=r[a.charCodeAt(p)];if(l===255)return;for(var w=0,C=x-1;(l!==0||w<m)&&C!==-1;C--,w++)l+=c*g[C]>>>0,g[C]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");m=w,p++}if(a[p]!==" "){for(var b=x-m;b!==x&&g[b]===0;)b++;for(var v=new Uint8Array(E+(x-b)),q=E;b!==x;)v[q++]=g[b++];return v}}}function qe(a){var p=k(a);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:B,decodeUnsafe:k,decode:qe}}var Ke=Ge,He=Ke,xe=He;var dr=new Uint8Array(0);var ge=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},A=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var we=t=>new TextEncoder().encode(t),ye=t=>new TextDecoder().decode(t);var Q=class{constructor(e,r,o){this.name=e,this.prefix=r,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},G=class{constructor(e,r,o){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=o}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only mu
|
||
|
|
return Uint8Arrays}));
|