Socket
Socket
Sign inDemoInstall

cbor-x

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cbor-x - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

2

dist/index.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.cbor=t():e.cbor=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";let n=r(1),i=n.Decoder,o=n.mult10;const s=n.typedArrays;let u,l,f;try{u=new TextEncoder}catch(e){}const c="undefined"!=typeof Buffer,a=c?Buffer.allocUnsafeSlow:Uint8Array,d=c?Buffer:Uint8Array;let h,g,y,p=0;const w=Symbol("record-id");function b(e,t,r,n,i){for(;n<i;)t[r++]=e[n++]}function U(e,t,r){h[p++]=204;let n=e.byteLength,i=e.byteOffset||0,o=e.buffer||e;r([t,c?Buffer.from(o,i,n):new Uint8Array(o,i,n)])}function O(e){let t=e.byteLength;t<256?(h[p++]=88,h[p++]=t):t<65536?(h[p++]=89,h[p++]=t>>8,h[p++]=255&t):(h[p++]=90,g.setUint32(p,t),p+=4),e.copy?e.copy(h,p):b(e,h,p,0,t),p+=t}t.Encoder=class extends i{constructor(e){let t,r,n,i,s;super(e),this.offset=0;let c=0,U=d.prototype.utf8Write?function(e,t,r){return h.utf8Write(e,t,r)}:!(!u||!u.encodeInto)&&function(e,t){return u.encodeInto(e,h.subarray(t)).written},O=this,m=64,v=e&&e.sequential;v&&(m=0,this.structures=[]);let x=[],j=0,A=0;if(this.structures&&this.structures.length>m)throw new Error("Too many shared structures");this.encode=function(e){if(h||(h=new a(8192),g=new DataView(h.buffer,0,8192),p=0),y=h.length-10,y-p<2048&&(h=new a(h.length),g=new DataView(h.buffer,0,h.length),y=h.length-10,p=0),t=p,s=O.structuredClone?new Map:null,r=O.structures,r){r.uninitialized&&(O.structures=r=O.getStructures());let e=r.length;if(e>m&&!v&&(e=m),!r.transitions){r.transitions=Object.create(null);for(let t=0;t<e;t++){let e=r[t];if(!e)continue;let n,i=r.transitions;for(let t=0,r=e.length;t<r;t++){let r=e[t];n=i[r],n||(n=i[r]=Object.create(null)),i=n}i[w]=t+64}c=r.length}v||(r.nextId=e+64)}n&&(n=!1),i=r||[];try{if(E(e),O.offset=p,s&&s.idsToInsert){p+=6*s.idsToInsert.length,p>y&&D(p),O.offset=p;let e=function(e,t){let r,n=6*t.length,i=e.length-n;t.sort((e,t)=>e.offset>t.offset?1:-1);for(;r=t.pop();){let t=r.offset,o=r.id;e.copyWithin(t+n,t,i),n-=6;let s=t+n;e[s++]=201,e[s++]=26,e[s++]=o<<24,e[s++]=o<<16&255,e[s++]=o<<8&255,e[s++]=255&o,i=t}return e}(h.subarray(t,p),s.idsToInsert);return s=null,e}return h.subarray(t,p)}finally{if(r){if(A<10&&A++,j>1e4)r.transitions=null,A=0,j=0,x.length>0&&(x=[]);else if(x.length>0&&!v){for(let e=0,t=x.length;e<t;e++)x[e][w]=0;x=[]}if(n&&O.saveStructures){if(O.structures.length>m&&(O.structures=O.structures.slice(0,m)),!1===O.saveStructures(O.structures,c))return O.structures=O.getStructures()||[],O.encode(e);c=O.structures.length}}}};const E=e=>{p>y&&(h=D(p));var r,n=typeof e;if("string"===n){let t,n=e.length;t=n<32?1:n<256?2:n<65536?3:5;let i=3*n;if(p+i>y&&(h=D(p+i)),n<64||!U){let i,o,s,u=p+t;for(i=0;i<n;i++)o=e.charCodeAt(i),o<128?h[u++]=o:o<2048?(h[u++]=o>>6|192,h[u++]=63&o|128):55296==(64512&o)&&56320==(64512&(s=e.charCodeAt(i+1)))?(o=65536+((1023&o)<<10)+(1023&s),i++,h[u++]=o>>18|240,h[u++]=o>>12&63|128,h[u++]=o>>6&63|128,h[u++]=63&o|128):(h[u++]=o>>12|224,h[u++]=o>>6&63|128,h[u++]=63&o|128);r=u-p-t}else r=U(e,p+t,i);r<24?h[p++]=96|r:r<256?(t<2&&h.copyWithin(p+2,p+1,p+1+r),h[p++]=120,h[p++]=r):r<65536?(t<3&&h.copyWithin(p+3,p+2,p+2+r),h[p++]=121,h[p++]=r>>8,h[p++]=255&r):(t<5&&h.copyWithin(p+5,p+3,p+3+r),h[p++]=122,g.setUint32(p,r),p+=4),p+=r}else if("number"===n)if(e>>>0===e)e<24?h[p++]=e:e<256?(h[p++]=24,h[p++]=e):e<65536?(h[p++]=25,h[p++]=e>>8,h[p++]=255&e):(h[p++]=26,g.setUint32(p,e),p+=4);else if(e>>0===e)e>=-24?h[p++]=31-e:e>=-256?(h[p++]=56,h[p++]=~e):e>=-65536?(h[p++]=57,g.setUint16(p,~e),p+=2):(h[p++]=58,g.setUint32(p,~e),p+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){let r;if(h[p++]=250,g.setFloat32(p,e),t<4||(r=e*o[(127&h[p])<<1|h[p+1]>>7])>>0===r)return void(p+=4);p--}h[p++]=251,g.setFloat64(p,e),p+=8}else if("object"===n)if(e){if(s){let r=s.get(e);if(r){if(!r.id){let e=s.idsToInsert||(s.idsToInsert=[]);r.id=e.push(r)}return h[p++]=202,h[p++]=26,g.setUint32(p,r.id),void(p+=4)}s.set(e,{offset:p-t})}let n=e.constructor;if(n===Object)S(e,!0);else if(n===Array){(r=e.length)<24?h[p++]=128|r:r<256?(h[p++]=152,h[p++]=r):r<65536?(h[p++]=153,h[p++]=r>>8,h[p++]=255&r):(h[p++]=154,g.setUint32(p,r),p+=4);for(let t=0;t<r;t++)E(e[t])}else if(n===Map){(r=e.size)<24?h[p++]=160|r:r<256?(h[p++]=184,h[p++]=r):r<65536?(h[p++]=185,h[p++]=r>>8,h[p++]=255&r):(h[p++]=186,g.setUint32(p,r),p+=4);for(let[t,r]of e)E(t),E(r)}else{for(let t=0,r=l.length;t<r;t++){if(e instanceof f[t]){let r=l[t],n=r.tag;return n<24?h[p++]=192|n:n<256?(h[p++]=216,h[p++]=n):n<65536?(h[p++]=217,h[p++]=n>>8,h[p++]=255&n):n>-1&&(h[p++]=186,g.setUint32(p,n),p+=4),void r.encode.call(this,e,E)}}S(e,!1)}}else h[p++]=246;else if("boolean"===n)h[p++]=e?245:244;else if("bigint"===n)h[p++]=251,g.setFloat64(p,e),p+=8;else{if("undefined"!==n)throw new Error("Unknown type "+n);h[p++]=247}},S=!1===this.useRecords?this.variableMapSize?e=>{let t,r=Object.keys(e),n=r.length;n<24?h[p++]=160|n:n<256?(h[p++]=184,h[p++]=n):n<65536?(h[p++]=185,h[p++]=n>>8,h[p++]=255&n):(h[p++]=186,g.setUint32(p,n),p+=4);for(let i=0;i<n;i++)E(t=r[i]),E(e[t])}:(e,r)=>{h[p++]=185;let n=p-t;p+=2;let i=0;for(let t in e)(r||e.hasOwnProperty(t))&&(E(t),E(e[t]),i++);h[n+++t]=i>>8,h[n+t]=255&i}:e=>{let t,o=Object.keys(e),s=i.transitions||(i.transitions=Object.create(null)),u=0;for(let e=0,r=o.length;e<r;e++){let r=o[e];t=s[r],t||(t=s[r]=Object.create(null),u++),s=t}let l=s[w];l?(h[p++]=216,h[p++]=l):(l=i.nextId++,l||(l=64,i.nextId=65),l>=256&&(i.nextId=(l=m+64)+1),s[w]=l,i[l-64]=o,r&&r.length<=m?(h[p++]=216,h[p++]=l,n=!0):(h[p++]=198,u&&(j+=A*u),x.length>=192-m&&(x.shift()[w]=0),x.push(s),E([l].concat(o))));for(let t=0,r=o.length;t<r;t++)E(e[o[t]])},D=e=>{let r=1+(Math.max(e-t<<2,h.length-1)>>12)<<12,n=new a(r);return g=new DataView(n.buffer,0,r),h.copy?h.copy(n,0,t,e):b(h,n,0,t,e),p-=t,t=0,y=n.length-10,h=n}}useBuffer(e){h=e,g=new DataView(h.buffer,h.byteOffset,h.byteLength),p=0}},f=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor],l=[{tag:1,encode(e,t){let r=e.getTime()/1e3;(this.useTimestamp32||0===e.getMilliseconds())&&r>=0&&r<4294967296?(h[p++]=26,g.setUint32(p,r),p+=4):(h[p++]=251,g.setFloat64(p,r),p+=8)}},{tag:11,encode(e,t){t(Array.from(e))}},{tag:8,encode(e,t){t([e.name,e.message])}},{tag:13,encode(e,t){t([e.source,e.flags])}},{encode(e,t){this.structuredClone?U(e,16,t):O(c?Buffer.from(e):new Uint8Array(e))}},{encode(e,t){let r=e.constructor;r!==d&&this.structuredClone?U(e,s.indexOf(r.name),t):O(e)}}],t.addExtension=function(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");f.unshift(e.Class),l.unshift(e)}n.addExtension(e)}},function(e,t,r){"use strict";(function(e){let r,n,i;try{r=new TextDecoder}catch(e){}let o=0;const s=[];let u,l,f,c,a=s,d=0,h={},g=0,y=0,p=[],w={useRecords:!1,mapsAsObjects:!0};class b{constructor(e){e&&(!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.getStructures&&!e.structures&&((e.structures=[]).uninitialized=!0)),Object.assign(this,e)}decode(e,t,r){if(n)return M(()=>(n=null,this?this.decode(e,t,r):b.prototype.decode.call(w,e,t,r)));if(i=t>-1?t:e.length,o=0,d=0,y=0,u=null,a=s,n=e,f=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength)),this)if(h=this,this.structures){c=this.structures;try{return U()}finally{(o>=i||!r)&&(c=null,n=null,l&&(l=null))}}else(!c||c.length>0)&&(c=[]);else h=w,(!c||c.length>0)&&(c=[]);try{return U()}finally{n=null,l&&(l=null)}}}function U(){let e=n[o++],t=e>>5;if(e&=31,e>23)switch(e){case 24:e=n[o++];break;case 25:if(7==t)return function(){let e,t=n[o++],r=n[o++],i=(t<<8)+r,s=i>>10&31,u=1023&i;e=0==s?Math.exp(u,-24):31!=s?Math.exp(u+1024,s-25):0==u?1/0:NaN;return 32768&i?-e:e}();e=f.getUint16(o),o+=2;break;case 26:if(7==t){let e=f.getFloat32(o);if(h.useFloat32>2){let t=C[(127&n[o])<<1|n[o+1]>>7];return o+=4,(t*e+(e>0?.5:-.5)>>0)/t}return o+=4,e}e=f.getUint32(o),o+=4;break;case 27:if(7==t){let e=f.getFloat64(o);return o+=8,e}if(h.uint64AsNumber)return 72057594037927940*n[o++]+281474976710656*n[o++]+1099511627776*n[o++]+4294967296*n[o++]+16777216*n[o++]+(n[o++]<<16)+(n[o++]<<8)+n[o++];e=f.getBigUint64(o),o+=8;break;default:throw new Error("Unknown token "+e)}switch(t){case 0:return e;case 1:return~e;case 2:return r=e,h.copyBuffers?Uint8Array.prototype.slice.call(n,o,o+=r):n.subarray(o,o+=r);case 3:if(y>=o)return u.slice(o-g,(o+=e)-g);if(0==y&&i<120&&e<16){let t=D(e);if(null!=t)return t}return v(e);case 4:let t=new Array(e);for(let r=0;r<e;r++)t[r]=U();return t;case 5:if(h.mapsAsObjects){let t={};for(let r=0;r<e;r++)t[U()]=U();return t}{let t=new Map;for(let r=0;r<e;r++)t.set(U(),U());return t}case 6:if(e>=64&&e<256){let t=c[e-64];if(t)return t.read||(t.read=m(t)),t.read();if(h.getStructures){let r=M(()=>(n=null,h.getStructures()));return!0===c?h.structures=c=r:c.splice.apply(c,[0,r.length].concat(r)),t=c[e-64],t?(t.read||(t.read=m(t)),t.read()):e}return e}if(p[e])return p[e](U());throw new Error("Unknown extension "+e);case 7:switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:throw new Error("Unknown token "+e)}default:if(isNaN(e)){let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}throw new Error("Unknown CBOR token "+e)}var r}t.Decoder=b,t.read=U,t.getPosition=()=>o;const O=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function m(e){function t(){if(t.count++>2)return this.read=new Function("r","return function(){return {"+e.map(e=>O.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}}")(U),this.read();let r={};for(let t=0,n=e.length;t<n;t++){r[e[t]]=U()}return r}return t.count=0,t}let v=E,x=E,j=E,A=E;function E(e){let t;if(e<16&&(t=D(e)))return t;if(e>64&&r)return r.decode(n.subarray(o,o+=e));const i=o+e,s=[];for(t="";o<i;){const e=n[o++];if(0==(128&e))s.push(e);else if(192==(224&e)){const t=63&n[o++];s.push((31&e)<<6|t)}else if(224==(240&e)){const t=63&n[o++],r=63&n[o++];s.push((31&e)<<12|t<<6|r)}else if(240==(248&e)){let t=(7&e)<<18|(63&n[o++])<<12|(63&n[o++])<<6|63&n[o++];t>65535&&(t-=65536,s.push(t>>>10&1023|55296),t=56320|1023&t),s.push(t)}else s.push(e);s.length>=4096&&(t+=S.apply(String,s),s.length=0)}return s.length>0&&(t+=S.apply(String,s)),t}t.setExtractor=e=>{function t(t){return function(t){let r=a[d++];null==r&&(a=e(o,i,t,n),d=0,r=a[d++]);let s=r.length;return s<=t?(o+=t,r):(u=r,g=o,y=o+s,o+=t,r.slice(0,t))}}v=t(1),x=t(2),j=t(3),A=t(5)};let S=String.fromCharCode;function D(e){if(e<4){if(e<2){if(0===e)return"";{let e=n[o++];return(128&e)>1?void(o-=1):S(e)}}{let t=n[o++],r=n[o++];if((128&t)>0||(128&r)>0)return void(o-=2);if(e<3)return S(t,r);let i=n[o++];return(128&i)>0?void(o-=3):S(t,r,i)}}{let t=n[o++],r=n[o++],i=n[o++],s=n[o++];if((128&t)>0||(128&r)>0||(128&i)>0||(128&s)>0)return void(o-=4);if(e<6){if(4===e)return S(t,r,i,s);{let e=n[o++];return(128&e)>0?void(o-=5):S(t,r,i,s,e)}}if(e<8){let u=n[o++],l=n[o++];if((128&u)>0||(128&l)>0)return void(o-=6);if(e<7)return S(t,r,i,s,u,l);let f=n[o++];return(128&f)>0?void(o-=7):S(t,r,i,s,u,l,f)}{let u=n[o++],l=n[o++],f=n[o++],c=n[o++];if((128&u)>0||(128&l)>0||(128&f)>0||(128&c)>0)return void(o-=8);if(e<10){if(8===e)return S(t,r,i,s,u,l,f,c);{let e=n[o++];return(128&e)>0?void(o-=9):S(t,r,i,s,u,l,f,c,e)}}if(e<12){let a=n[o++],d=n[o++];if((128&a)>0||(128&d)>0)return void(o-=10);if(e<11)return S(t,r,i,s,u,l,f,c,a,d);let h=n[o++];return(128&h)>0?void(o-=11):S(t,r,i,s,u,l,f,c,a,d,h)}{let a=n[o++],d=n[o++],h=n[o++],g=n[o++];if((128&a)>0||(128&d)>0||(128&h)>0||(128&g)>0)return void(o-=12);if(e<14){if(12===e)return S(t,r,i,s,u,l,f,c,a,d,h,g);{let e=n[o++];return(128&e)>0?void(o-=13):S(t,r,i,s,u,l,f,c,a,d,h,g,e)}}{let y=n[o++],p=n[o++];if((128&y)>0||(128&p)>0)return void(o-=14);if(e<15)return S(t,r,i,s,u,l,f,c,a,d,h,g,y,p);let w=n[o++];return(128&w)>0?void(o-=15):S(t,r,i,s,u,l,f,c,a,d,h,g,y,p,w)}}}}}let I="object"==typeof window?window:e;p[0]=e=>new Date(e),p[1]=e=>new Date(1e3*e),p[2]=e=>new DataView(e.buffer,e.byteOffset,e.byteLength).getBigUint64(0),p[3]=e=>BigInt(-1)-new DataView(e.buffer,e.byteOffset,e.byteLength).getBigUint64(0),p[6]=e=>{let t=e[0];return e=e.slice(1),c[t-64]=e,e.read=m(e),e.read()},p[8]=e=>(I[e[0]]||Error)(e[1]),p[9]=e=>{let t;l||(l=new Map),t=n[o]>>5==4?[]:{};let r={target:t};l.set(e,r);let i=U();return r.used?Object.assign(t,i):(r.target=i,i)},p[10]=e=>{let t=l.get(e);return t.used=!0,t.target},p[11]=e=>new Set(e);const B=["Int8","Uint8\t","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");function M(e){let t=i,r=o,s=d,p=g,w=y,b=u,U=a,O=l,m=new Uint8Array(n.slice(0,i)),v=c,x=h,j=e();return i=t,o=r,d=s,g=p,y=w,u=b,a=U,l=O,n=m,c=v,h=x,f=new DataView(n.buffer,n.byteOffset,n.byteLength),j}p[12]=e=>{let[t,r]=e,n=B[t];if(!n)throw new Error("Could not find typed array for code "+t);return new I[n](Uint8Array.prototype.slice.call(r,0).buffer)},p[13]=e=>new RegExp(e[0],e[1]),t.clearSource=function(){n=null},t.addExtension=function(e){p[e.tag]=e.decode};let C=new Array(147);for(let e=0;e<256;e++)C[e]=+("1e"+Math.floor(45.15-.30103*e));t.mult10=C,t.typedArrays=B}).call(this,r(3))},function(e,t,r){t.Encoder=r(0).Encoder,t.Decoder=r(1).Decoder,t.addExtension=r(0).addExtension;let n=new t.Encoder({useRecords:!1});t.decode=n.decode,t.encode=n.encode,Object.assign(t,{ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4})},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r}])}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CBOR=t():e.CBOR=t()}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){"use strict";let n=r(1),i=n.Decoder,o=n.mult10;const s=n.typedArrays;let u,l,f;try{u=new TextEncoder}catch(e){}const c="undefined"!=typeof Buffer,a=c?Buffer.allocUnsafeSlow:Uint8Array,d=c?Buffer:Uint8Array;let h,g,y,p=0;const w=Symbol("record-id");function b(e,t,r,n,i){for(;n<i;)t[r++]=e[n++]}function O(e,t,r){h[p++]=204;let n=e.byteLength,i=e.byteOffset||0,o=e.buffer||e;r([t,c?Buffer.from(o,i,n):new Uint8Array(o,i,n)])}function U(e){let t=e.byteLength;t<256?(h[p++]=88,h[p++]=t):t<65536?(h[p++]=89,h[p++]=t>>8,h[p++]=255&t):(h[p++]=90,g.setUint32(p,t),p+=4),e.copy?e.copy(h,p):b(e,h,p,0,t),p+=t}t.Encoder=class extends i{constructor(e){let t,r,n,i,s;super(e),this.offset=0;let c=0,O=d.prototype.utf8Write?function(e,t,r){return h.utf8Write(e,t,r)}:!(!u||!u.encodeInto)&&function(e,t){return u.encodeInto(e,h.subarray(t)).written},U=this,m=64,v=e&&e.sequential;v&&(m=0,this.structures=[]);let x=[],j=0,A=0;if(this.structures&&this.structures.length>m)throw new Error("Too many shared structures");this.encode=function(e){if(h||(h=new a(8192),g=new DataView(h.buffer,0,8192),p=0),y=h.length-10,y-p<2048&&(h=new a(h.length),g=new DataView(h.buffer,0,h.length),y=h.length-10,p=0),t=p,s=U.structuredClone?new Map:null,r=U.structures,r){r.uninitialized&&(U.structures=r=U.getStructures());let e=r.length;if(e>m&&!v&&(e=m),!r.transitions){r.transitions=Object.create(null);for(let t=0;t<e;t++){let e=r[t];if(!e)continue;let n,i=r.transitions;for(let t=0,r=e.length;t<r;t++){let r=e[t];n=i[r],n||(n=i[r]=Object.create(null)),i=n}i[w]=t+64}c=r.length}v||(r.nextId=e+64)}n&&(n=!1),i=r||[];try{if(E(e),U.offset=p,s&&s.idsToInsert){p+=6*s.idsToInsert.length,p>y&&D(p),U.offset=p;let e=function(e,t){let r,n=6*t.length,i=e.length-n;t.sort((e,t)=>e.offset>t.offset?1:-1);for(;r=t.pop();){let t=r.offset,o=r.id;e.copyWithin(t+n,t,i),n-=6;let s=t+n;e[s++]=201,e[s++]=26,e[s++]=o<<24,e[s++]=o<<16&255,e[s++]=o<<8&255,e[s++]=255&o,i=t}return e}(h.subarray(t,p),s.idsToInsert);return s=null,e}return h.subarray(t,p)}finally{if(r){if(A<10&&A++,j>1e4)r.transitions=null,A=0,j=0,x.length>0&&(x=[]);else if(x.length>0&&!v){for(let e=0,t=x.length;e<t;e++)x[e][w]=0;x=[]}if(n&&U.saveStructures){if(U.structures.length>m&&(U.structures=U.structures.slice(0,m)),!1===U.saveStructures(U.structures,c))return U.structures=U.getStructures()||[],U.encode(e);c=U.structures.length}}}};const E=e=>{p>y&&(h=D(p));var r,n=typeof e;if("string"===n){let t,n=e.length;t=n<32?1:n<256?2:n<65536?3:5;let i=3*n;if(p+i>y&&(h=D(p+i)),n<64||!O){let i,o,s,u=p+t;for(i=0;i<n;i++)o=e.charCodeAt(i),o<128?h[u++]=o:o<2048?(h[u++]=o>>6|192,h[u++]=63&o|128):55296==(64512&o)&&56320==(64512&(s=e.charCodeAt(i+1)))?(o=65536+((1023&o)<<10)+(1023&s),i++,h[u++]=o>>18|240,h[u++]=o>>12&63|128,h[u++]=o>>6&63|128,h[u++]=63&o|128):(h[u++]=o>>12|224,h[u++]=o>>6&63|128,h[u++]=63&o|128);r=u-p-t}else r=O(e,p+t,i);r<24?h[p++]=96|r:r<256?(t<2&&h.copyWithin(p+2,p+1,p+1+r),h[p++]=120,h[p++]=r):r<65536?(t<3&&h.copyWithin(p+3,p+2,p+2+r),h[p++]=121,h[p++]=r>>8,h[p++]=255&r):(t<5&&h.copyWithin(p+5,p+3,p+3+r),h[p++]=122,g.setUint32(p,r),p+=4),p+=r}else if("number"===n)if(e>>>0===e)e<24?h[p++]=e:e<256?(h[p++]=24,h[p++]=e):e<65536?(h[p++]=25,h[p++]=e>>8,h[p++]=255&e):(h[p++]=26,g.setUint32(p,e),p+=4);else if(e>>0===e)e>=-24?h[p++]=31-e:e>=-256?(h[p++]=56,h[p++]=~e):e>=-65536?(h[p++]=57,g.setUint16(p,~e),p+=2):(h[p++]=58,g.setUint32(p,~e),p+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){let r;if(h[p++]=250,g.setFloat32(p,e),t<4||(r=e*o[(127&h[p])<<1|h[p+1]>>7])>>0===r)return void(p+=4);p--}h[p++]=251,g.setFloat64(p,e),p+=8}else if("object"===n)if(e){if(s){let r=s.get(e);if(r){if(!r.id){let e=s.idsToInsert||(s.idsToInsert=[]);r.id=e.push(r)}return h[p++]=202,h[p++]=26,g.setUint32(p,r.id),void(p+=4)}s.set(e,{offset:p-t})}let n=e.constructor;if(n===Object)S(e,!0);else if(n===Array){(r=e.length)<24?h[p++]=128|r:r<256?(h[p++]=152,h[p++]=r):r<65536?(h[p++]=153,h[p++]=r>>8,h[p++]=255&r):(h[p++]=154,g.setUint32(p,r),p+=4);for(let t=0;t<r;t++)E(e[t])}else if(n===Map){(r=e.size)<24?h[p++]=160|r:r<256?(h[p++]=184,h[p++]=r):r<65536?(h[p++]=185,h[p++]=r>>8,h[p++]=255&r):(h[p++]=186,g.setUint32(p,r),p+=4);for(let[t,r]of e)E(t),E(r)}else{for(let t=0,r=l.length;t<r;t++){if(e instanceof f[t]){let r=l[t],n=r.tag;return n<24?h[p++]=192|n:n<256?(h[p++]=216,h[p++]=n):n<65536?(h[p++]=217,h[p++]=n>>8,h[p++]=255&n):n>-1&&(h[p++]=186,g.setUint32(p,n),p+=4),void r.encode.call(this,e,E)}}S(e,!1)}}else h[p++]=246;else if("boolean"===n)h[p++]=e?245:244;else if("bigint"===n)h[p++]=251,g.setFloat64(p,e),p+=8;else{if("undefined"!==n)throw new Error("Unknown type "+n);h[p++]=247}},S=!1===this.useRecords?this.variableMapSize?e=>{let t,r=Object.keys(e),n=r.length;n<24?h[p++]=160|n:n<256?(h[p++]=184,h[p++]=n):n<65536?(h[p++]=185,h[p++]=n>>8,h[p++]=255&n):(h[p++]=186,g.setUint32(p,n),p+=4);for(let i=0;i<n;i++)E(t=r[i]),E(e[t])}:(e,r)=>{h[p++]=185;let n=p-t;p+=2;let i=0;for(let t in e)(r||e.hasOwnProperty(t))&&(E(t),E(e[t]),i++);h[n+++t]=i>>8,h[n+t]=255&i}:e=>{let t,o=Object.keys(e),s=i.transitions||(i.transitions=Object.create(null)),u=0;for(let e=0,r=o.length;e<r;e++){let r=o[e];t=s[r],t||(t=s[r]=Object.create(null),u++),s=t}let l=s[w];l?(h[p++]=216,h[p++]=l):(l=i.nextId++,l||(l=64,i.nextId=65),l>=256&&(i.nextId=(l=m+64)+1),s[w]=l,i[l-64]=o,r&&r.length<=m?(h[p++]=216,h[p++]=l,n=!0):(h[p++]=198,u&&(j+=A*u),x.length>=192-m&&(x.shift()[w]=0),x.push(s),E([l].concat(o))));for(let t=0,r=o.length;t<r;t++)E(e[o[t]])},D=e=>{let r=1+(Math.max(e-t<<2,h.length-1)>>12)<<12,n=new a(r);return g=new DataView(n.buffer,0,r),h.copy?h.copy(n,0,t,e):b(h,n,0,t,e),p-=t,t=0,y=n.length-10,h=n}}useBuffer(e){h=e,g=new DataView(h.buffer,h.byteOffset,h.byteLength),p=0}},f=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor],l=[{tag:1,encode(e,t){let r=e.getTime()/1e3;(this.useTimestamp32||0===e.getMilliseconds())&&r>=0&&r<4294967296?(h[p++]=26,g.setUint32(p,r),p+=4):(h[p++]=251,g.setFloat64(p,r),p+=8)}},{tag:11,encode(e,t){t(Array.from(e))}},{tag:8,encode(e,t){t([e.name,e.message])}},{tag:13,encode(e,t){t([e.source,e.flags])}},{encode(e,t){this.structuredClone?O(e,16,t):U(c?Buffer.from(e):new Uint8Array(e))}},{encode(e,t){let r=e.constructor;r!==d&&this.structuredClone?O(e,s.indexOf(r.name),t):U(e)}}],t.addExtension=function(e){if(e.Class){if(!e.encode)throw new Error("Extension has no encode function");f.unshift(e.Class),l.unshift(e)}n.addExtension(e)}},function(e,t,r){"use strict";(function(e){let r,n,i;try{r=new TextDecoder}catch(e){}let o=0;const s=[];let u,l,f,c,a=s,d=0,h={},g=0,y=0,p=[],w={useRecords:!1,mapsAsObjects:!0};class b{constructor(e){e&&(!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.getStructures&&!e.structures&&((e.structures=[]).uninitialized=!0)),Object.assign(this,e)}decode(e,t,r){if(n)return C(()=>(n=null,this?this.decode(e,t,r):b.prototype.decode.call(w,e,t,r)));if(i=t>-1?t:e.length,o=0,d=0,y=0,u=null,a=s,n=e,f=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength)),this)if(h=this,this.structures){c=this.structures;try{return O()}finally{(o>=i||!r)&&(c=null,n=null,l&&(l=null))}}else(!c||c.length>0)&&(c=[]);else h=w,(!c||c.length>0)&&(c=[]);try{return O()}finally{n=null,l&&(l=null)}}}function O(){let e=n[o++],t=e>>5;if(e&=31,e>23)switch(e){case 24:e=n[o++];break;case 25:if(7==t)return function(){let e,t=n[o++],r=n[o++],i=(t<<8)+r,s=i>>10&31,u=1023&i;e=0==s?Math.exp(u,-24):31!=s?Math.exp(u+1024,s-25):0==u?1/0:NaN;return 32768&i?-e:e}();e=f.getUint16(o),o+=2;break;case 26:if(7==t){let e=f.getFloat32(o);if(h.useFloat32>2){let t=M[(127&n[o])<<1|n[o+1]>>7];return o+=4,(t*e+(e>0?.5:-.5)>>0)/t}return o+=4,e}e=f.getUint32(o),o+=4;break;case 27:if(7==t){let e=f.getFloat64(o);return o+=8,e}if(h.uint64AsNumber)return 72057594037927940*n[o++]+281474976710656*n[o++]+1099511627776*n[o++]+4294967296*n[o++]+16777216*n[o++]+(n[o++]<<16)+(n[o++]<<8)+n[o++];e=f.getBigUint64(o),o+=8;break;default:throw new Error("Unknown token "+e)}switch(t){case 0:return e;case 1:return~e;case 2:return r=e,h.copyBuffers?Uint8Array.prototype.slice.call(n,o,o+=r):n.subarray(o,o+=r);case 3:if(y>=o)return u.slice(o-g,(o+=e)-g);if(0==y&&i<120&&e<16){let t=D(e);if(null!=t)return t}return v(e);case 4:let t=new Array(e);for(let r=0;r<e;r++)t[r]=O();return t;case 5:if(h.mapsAsObjects){let t={};for(let r=0;r<e;r++)t[O()]=O();return t}{let t=new Map;for(let r=0;r<e;r++)t.set(O(),O());return t}case 6:if(e>=64&&e<256){let t=c[e-64];if(t)return t.read||(t.read=m(t)),t.read();if(h.getStructures){let r=C(()=>(n=null,h.getStructures()));return!0===c?h.structures=c=r:c.splice.apply(c,[0,r.length].concat(r)),t=c[e-64],t?(t.read||(t.read=m(t)),t.read()):e}return e}if(p[e])return p[e](O());throw new Error("Unknown extension "+e);case 7:switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:throw new Error("Unknown token "+e)}default:if(isNaN(e)){let e=new Error("Unexpected end of CBOR data");throw e.incomplete=!0,e}throw new Error("Unknown CBOR token "+e)}var r}t.Decoder=b,t.read=O,t.getPosition=()=>o;const U=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function m(e){function t(){if(t.count++>2)return this.read=new Function("r","return function(){return {"+e.map(e=>U.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}}")(O),this.read();let r={};for(let t=0,n=e.length;t<n;t++){r[e[t]]=O()}return r}return t.count=0,t}let v=E,x=E,j=E,A=E;function E(e){let t;if(e<16&&(t=D(e)))return t;if(e>64&&r)return r.decode(n.subarray(o,o+=e));const i=o+e,s=[];for(t="";o<i;){const e=n[o++];if(0==(128&e))s.push(e);else if(192==(224&e)){const t=63&n[o++];s.push((31&e)<<6|t)}else if(224==(240&e)){const t=63&n[o++],r=63&n[o++];s.push((31&e)<<12|t<<6|r)}else if(240==(248&e)){let t=(7&e)<<18|(63&n[o++])<<12|(63&n[o++])<<6|63&n[o++];t>65535&&(t-=65536,s.push(t>>>10&1023|55296),t=56320|1023&t),s.push(t)}else s.push(e);s.length>=4096&&(t+=S.apply(String,s),s.length=0)}return s.length>0&&(t+=S.apply(String,s)),t}t.setExtractor=e=>{function t(t){return function(t){let r=a[d++];null==r&&(a=e(o,i,t,n),d=0,r=a[d++]);let s=r.length;return s<=t?(o+=t,r):(u=r,g=o,y=o+s,o+=t,r.slice(0,t))}}v=t(1),x=t(2),j=t(3),A=t(5)};let S=String.fromCharCode;function D(e){if(e<4){if(e<2){if(0===e)return"";{let e=n[o++];return(128&e)>1?void(o-=1):S(e)}}{let t=n[o++],r=n[o++];if((128&t)>0||(128&r)>0)return void(o-=2);if(e<3)return S(t,r);let i=n[o++];return(128&i)>0?void(o-=3):S(t,r,i)}}{let t=n[o++],r=n[o++],i=n[o++],s=n[o++];if((128&t)>0||(128&r)>0||(128&i)>0||(128&s)>0)return void(o-=4);if(e<6){if(4===e)return S(t,r,i,s);{let e=n[o++];return(128&e)>0?void(o-=5):S(t,r,i,s,e)}}if(e<8){let u=n[o++],l=n[o++];if((128&u)>0||(128&l)>0)return void(o-=6);if(e<7)return S(t,r,i,s,u,l);let f=n[o++];return(128&f)>0?void(o-=7):S(t,r,i,s,u,l,f)}{let u=n[o++],l=n[o++],f=n[o++],c=n[o++];if((128&u)>0||(128&l)>0||(128&f)>0||(128&c)>0)return void(o-=8);if(e<10){if(8===e)return S(t,r,i,s,u,l,f,c);{let e=n[o++];return(128&e)>0?void(o-=9):S(t,r,i,s,u,l,f,c,e)}}if(e<12){let a=n[o++],d=n[o++];if((128&a)>0||(128&d)>0)return void(o-=10);if(e<11)return S(t,r,i,s,u,l,f,c,a,d);let h=n[o++];return(128&h)>0?void(o-=11):S(t,r,i,s,u,l,f,c,a,d,h)}{let a=n[o++],d=n[o++],h=n[o++],g=n[o++];if((128&a)>0||(128&d)>0||(128&h)>0||(128&g)>0)return void(o-=12);if(e<14){if(12===e)return S(t,r,i,s,u,l,f,c,a,d,h,g);{let e=n[o++];return(128&e)>0?void(o-=13):S(t,r,i,s,u,l,f,c,a,d,h,g,e)}}{let y=n[o++],p=n[o++];if((128&y)>0||(128&p)>0)return void(o-=14);if(e<15)return S(t,r,i,s,u,l,f,c,a,d,h,g,y,p);let w=n[o++];return(128&w)>0?void(o-=15):S(t,r,i,s,u,l,f,c,a,d,h,g,y,p,w)}}}}}let I="object"==typeof window?window:e;p[0]=e=>new Date(e),p[1]=e=>new Date(1e3*e),p[2]=e=>new DataView(e.buffer,e.byteOffset,e.byteLength).getBigUint64(0),p[3]=e=>BigInt(-1)-new DataView(e.buffer,e.byteOffset,e.byteLength).getBigUint64(0),p[6]=e=>{let t=e[0];return e=e.slice(1),c[t-64]=e,e.read=m(e),e.read()},p[8]=e=>(I[e[0]]||Error)(e[1]),p[9]=e=>{let t;l||(l=new Map),t=n[o]>>5==4?[]:{};let r={target:t};l.set(e,r);let i=O();return r.used?Object.assign(t,i):(r.target=i,i)},p[10]=e=>{let t=l.get(e);return t.used=!0,t.target},p[11]=e=>new Set(e);const B=["Int8","Uint8\t","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");function C(e){let t=i,r=o,s=d,p=g,w=y,b=u,O=a,U=l,m=new Uint8Array(n.slice(0,i)),v=c,x=h,j=e();return i=t,o=r,d=s,g=p,y=w,u=b,a=O,l=U,n=m,c=v,h=x,f=new DataView(n.buffer,n.byteOffset,n.byteLength),j}p[12]=e=>{let[t,r]=e,n=B[t];if(!n)throw new Error("Could not find typed array for code "+t);return new I[n](Uint8Array.prototype.slice.call(r,0).buffer)},p[13]=e=>new RegExp(e[0],e[1]),t.clearSource=function(){n=null},t.addExtension=function(e){p[e.tag]=e.decode};let M=new Array(147);for(let e=0;e<256;e++)M[e]=+("1e"+Math.floor(45.15-.30103*e));t.mult10=M,t.typedArrays=B}).call(this,r(3))},function(e,t,r){t.Encoder=r(0).Encoder,t.Decoder=r(1).Decoder,t.addExtension=r(0).addExtension;let n=new t.Encoder({useRecords:!1});t.decode=n.decode,t.encode=n.encode,Object.assign(t,{ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4})},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r}])}));
//# sourceMappingURL=index.js.map
{
"name": "cbor-x",
"author": "Kris Zyp",
"version": "0.4.1",
"version": "0.4.2",
"license": "MIT",

@@ -6,0 +6,0 @@ "types": "./index.d.ts",

@@ -59,3 +59,3 @@ # cbor-x

This is UMD based, and will register as a module if possible, or create a `cbor` global with all the exported functions.
This is UMD based, and will register as a module if possible, or create a `CBOR` global with all the exported functions.

@@ -62,0 +62,0 @@ For module-based development, it is recommended that you directly import the module of interest, to minimize dependencies that get pulled into your application:

@@ -13,11 +13,11 @@ //var inspector = require('inspector')

assert = chai.assert
if (typeof cbor === 'undefined') { cbor = require('..') }
var Encoder = cbor.Encoder
var EncoderStream = cbor.EncoderStream
var DecoderStream = cbor.DecoderStream
var decode = cbor.decode
var encode = cbor.encode
var DECIMAL_FIT = cbor.DECIMAL_FIT
if (typeof CBOR === 'undefined') { CBOR = require('..') }
var Encoder = CBOR.Encoder
var EncoderStream = CBOR.EncoderStream
var DecoderStream = CBOR.DecoderStream
var decode = CBOR.decode
var encode = CBOR.encode
var DECIMAL_FIT = CBOR.DECIMAL_FIT
var addExtension = cbor.addExtension
var addExtension = CBOR.addExtension

@@ -46,3 +46,3 @@ var zlib = tryRequire('zlib')

suite('cbor basic tests', function(){
suite('CBOR basic tests', function(){
test('encode/decode data', function(){

@@ -152,3 +152,3 @@ var data = {

let s = td.decode(b)
if (!require('cbor-extract').isOneByte(s)) {
if (!require('CBOR-extract').isOneByte(s)) {
console.log(i.toString(16), s.length)

@@ -354,3 +354,3 @@ total++

})
suite('cbor performance tests', function(){
suite('CBOR performance tests', function(){
test('performance JSON.parse', function() {

@@ -381,3 +381,3 @@ var data = sampleData

var serialized = encoder.encode(data)
console.log('cbor w/ record ext size', serialized.length)
console.log('CBOR w/ record ext size', serialized.length)
for (var i = 0; i < ITERATIONS; i++) {

@@ -384,0 +384,0 @@ var deserialized = encoder.decode(serialized)

@@ -9,3 +9,3 @@ var webpack = require('webpack')

path: path.join(__dirname, 'dist'),
library: 'cbor',
library: 'CBOR',
libraryTarget: 'umd'

@@ -12,0 +12,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc