cbor2
Version:
Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).
2 lines (1 loc) • 965 B
JavaScript
import{SYMS as i}from"./constants.js";import{Tag as o}from"./tag.js";function f(n){if(n!=null&&typeof n=="object")return n[i.ENCODED]}function s(n){if(n!=null&&typeof n=="object")return n[i.LENGTH]}function u(n,e){Object.defineProperty(n,i.ENCODED,{configurable:!0,enumerable:!1,value:e})}function l(n,e){Object.defineProperty(n,i.LENGTH,{configurable:!0,enumerable:!1,value:e})}function d(n,e){const r=Object(n);return u(r,e),r}function t(n){if(!n||typeof n!="object")return n;switch(n.constructor){case BigInt:case Boolean:case Number:case String:case Symbol:return n.valueOf();case Array:return n.map(e=>t(e));case Map:{const e=t([...n.entries()]);return e.every(([r])=>typeof r=="string")?Object.fromEntries(e):new Map(e)}case o:return new o(t(n.tag),t(n.contents));case Object:{const e={};for(const[r,a]of Object.entries(n))e[r]=t(a);return e}}return n}export{d as box,f as getEncoded,s as getEncodedLength,u as saveEncoded,l as saveEncodedLength,t as unbox};