4 lines
33 KiB
JavaScript
4 lines
33 KiB
JavaScript
|
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldDagCbor = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
||
|
|
"use strict";var IpldDagCbor=(()=>{var Ae=Object.defineProperty;var ur=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var fr=Object.prototype.hasOwnProperty;var lr=(e,t)=>{for(var r in t)Ae(e,r,{get:t[r],enumerable:!0})},pr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of dr(t))!fr.call(e,o)&&o!==r&&Ae(e,o,{get:()=>t[o],enumerable:!(n=ur(t,o))||n.enumerable});return e};var hr=e=>pr(Ae({},"__esModule",{value:!0}),e);var _n={};lr(_n,{code:()=>Sn,decode:()=>Nn,encode:()=>Bn,name:()=>kn});var mr=["string","number","bigint","symbol"],yr=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Pe(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(mr.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(gr(e))return"Buffer";let r=wr(e);return r||"Object"}function gr(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function wr(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(yr.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var a=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var J=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",br=new TextDecoder,xr=new TextEncoder;function he(e){return J&&globalThis.Buffer.isBuffer(e)}function Te(e){return e instanceof Uint8Array?he(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Je=J?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):qe(e,t,r):(e,t,r)=>r-t>64?br.decode(e.subarray(t,r)):qe(e,t,r),Ke=J?e=>e.length>64?globalThis.Buffer.from(e):je(e):e=>e.length>64?xr.encode(e):je(e),z=e=>Uint8Array.from(e),K=J?(e,t,r)=>he(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Xe=J?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Te(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},He=J?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Qe(e,t){if(he(e)&&he(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function je(e,t=1/0){let r,n=e.length,o=null,i=[];for(let u=0;u<n;++u){if(r=e.charCodeAt(u),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(u+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function qe(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,u=o>239?
|
||
|
|
return IpldDagCbor}));
|