cborkit
Version:
A modern, extensible CBOR (Concise Binary Object Representation) library for TypeScript and JavaScript.
2 lines (1 loc) • 562 B
JavaScript
import{b as n,c}from"./chunk-2WDY66DD.js";var s,a,T=class{constructor(e=[]){c(this,s,new Map);c(this,a,new Map);e.forEach(r=>this.register(r))}get encoder(){return{object:(e,r,o)=>{if(e===null)return r();let t=n(this,s).get(e.constructor);return t?{type:"tag",value:t.tag,item:t.encode(e,o)}:r()}}}get decoder(){return{tag:(e,r,o)=>{let t=n(this,a).get(BigInt(e.value));return t?t(e.item,o):r()}}}register({target:e,tag:r,encode:o,decode:t}){n(this,s).set(e,{tag:r,encode:o}),n(this,a).set(BigInt(r),t)}};s=new WeakMap,a=new WeakMap;var b=d=>d;export{T as a,b};