1.6.6 • Published 9 months ago
@harmoniclabs/cbor v1.6.6
CBOR (Concise Binary Object Representation)
Installation
npm install @harmoniclabs/cborGetting started
import { Cbor, CborText } from "@harmoniclabs/cbor";
const input = "6B68656C6C6F20776F726C64";
const cborObj = Cbor.parse( input );
if( cborObj instanceof CborText )
{
console.log( cborObj.text ) // prints "hello world"
}
const encoded = Cbor.encode( cborObj ).toString();
console.log( encoded ) // prints "6b68656c6c6f20776f726c64" (lower case hex)How to use
Cbor
to parse/encode CBOR you can use the Cbor static class.
export declare class Cbor {
private constructor();
static encode(cborObj: CborObj): CborString;
static parse(cbor: CborString | Uint8Array | string): CborObj;
}parse allows you to go from a thing that can represent CBOR (a CborString object is always valid) to a CborObj
encode takes a CborObj and returns a CborString.
CborString
is an object that represents a valid CBOR string;
extending a ByteString includes:
toStringmethod that returns a lower case hex string.toBuffermethod that returns theUint8Arrayrepresentation of the string.
class CborString {
toString(): string
toBuffer(): Uint8Array
}CborObj
result of Cbor.parse; represents a generic CBOR tag corresponding to one of the possible Major types.
type CborObj
= CborNegInt
| CborUInt
| CborBytes
| CborText
| CborArray
| CborMap
| CborTag
| CborSimple;1.6.4
10 months ago
1.6.3
10 months ago
1.6.2
10 months ago
1.6.1
10 months ago
1.6.0
11 months ago
1.5.0
1 year ago
1.4.0
1 year ago
1.6.6
9 months ago
1.6.5
10 months ago
1.3.0
2 years ago
1.2.0
2 years ago
1.1.5
2 years ago
1.1.3-dev0
2 years ago
1.2.0-dev0
2 years ago
1.1.4
2 years ago
1.1.3-dev3
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.0
3 years ago