transformCBORValueToNative()

Transforms the CBOR values to native JS values.

Values are decoded as:

  • Positive integers (CBORPositiveInteger): Number or BigInt depending on the size.
  • Negative integers (CBORNegativeInteger): Number or BigInt depending on the size.
  • Byte strings (CBORByteString): Uint8Array.
  • Text strings (CBORTextString): String. Those with invalid UTF-8 encoding are considered invalid.
  • Arrays (CBORArray): Array of transformed values.
  • Maps (CBORMap): JS object where integer and float keys are converted to strings with Number.toString(). As such, integer 1 and float 1.0 are considered the same key. Maps with duplicate keys after stringify-ing them are considered invalid. Maps with the text key __proto__ are also considered invalid.
  • Floats (CBORFloat16, CBORFloat32, CBORFloat64): Number. This may cause minor accuracy issues for float16 and 32.
  • Simple values (CBORSimple): true, false, null, undefined. Everything else is considered invalid.
  • Tagged values (CBORTagged): Tags are ignored and the underlying value is transformed.

Unlike decodeCBOR(), this also validates the data and will throw CBORInvalidError on invalid data.

Definition

function transformCBORValueToNative(cbor: CBORValue): unknown;

Parameters

  • cbor: CBOR values except for breaks.