cbor-js
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/cbor-js package

0.1.0 • Public • Published

cbor-js

The Concise Binary Object Representation (CBOR) data format (RFC 7049) implemented in pure JavaScript.

Build Status Coverage Status Dependency status Dev Dependency Status Selenium Test Status

Selenium Test Status

API

The CBOR-object provides the following two functions:

CBOR.decode(data)

Take the ArrayBuffer object data and return it decoded as a JavaScript object.

CBOR.encode(data)

Take the JavaScript object data and return it encoded as a ArrayBuffer object.

Usage

Include cbor.js in your or HTML page:

<script src="path/to/cbor.js" type="text/javascript"></script>

Then you can use it via the CBOR-object in your code:

var initial = { Hello: "World" };
var encoded = CBOR.encode(initial);
var decoded = CBOR.decode(encoded);

After running this example initial and decoded represent the same value.

Combination with WebSocket

The API was designed to play well with the WebSocket object in the browser:

var websocket = new WebSocket(url);
websocket.binaryType = "arraybuffer";
...
websocket.onmessage = function(event) {
  var message = CBOR.decode(event.data);
};
...
websocket.send(CBOR.encode(message));

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    199,346
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    199,346

Package Sidebar

Install

npm i cbor-js

Weekly Downloads

158,510

Version

0.1.0

License

MIT

Last publish

Collaborators

  • letmaik
  • paroga