The Concise Binary Object Representation (CBOR) data format (RFC7049) implemented in pure JavaScript, revived.
npm install cbor-redux-typed-arraysThe Concise Binary Object Representation (CBOR) data format (RFC 7049) implemented in pure JavaScript, revived. Typed arrays such as Uint8Array, Int16Array or Float32Array are encoded with tags according to RFC8746 CBOR tags for Typed Arrays.
Rewritten in TypeScript for the browser, Deno, and Node.


!GitHub last commit
!GitHub contributors
!npm collaborators
!GitHub top language
!npm bundle size
!GitHub code size in bytes
!npm
!NPM




Require cbor-redux in Node:
``javascript`
const { CBOR } = require('cbor-redux')
or import in Deno:
`javascript`
import { CBOR } from 'https://deno.land/x/cbor_redux@0.4.0/mod.ts'
or script on an HTML page:
`html`
> For ES5 polyfill, use es5/CBOR.js in the npm package or else .
Then you can use it via the CBOR-object in your code:
`javascript`
const initial = { Hello: 'World' }
const encoded = CBOR.encode(initial)
const decoded = CBOR.decode(encoded)
After running this example initial and decoded represent the same value.
The CBOR-object provides the following two functions:
- CBOR._decode_(_data: ArrayBuffer_)
> Take the ArrayBuffer object _data_ and return it decoded as a JavaScript object.
- CBOR._encode_(_data: any_)
> Take the JavaScript object _data_ and return it encoded as a ArrayBuffer object.
For complete API details, visit the documentation.
The API was designed to play well with the WebSocket object in the browser:
`javascript``
var websocket = new WebSocket(url);
websocket.binaryType = "arraybuffer";
...
websocket.onmessage = function(event) {
var message = CBOR.decode(event.data);
};
...
websocket.send(CBOR.encode(message));