Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jprochazk/cbor

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jprochazk/cbor

Partial implementation of RFC 7049 (CBOR)

  • 0.2.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
86
increased by145.71%
Maintainers
1
Weekly downloads
 
Created
Source

cbor

JavaScript implementation of the CBOR RFC 7049.

David GitHub

Usage

This library is meant for use in the browser, but will also work in Node.

> npm install @jprochazk/cbor

The API is very simple:

import CBOR from "@jprochazk/cbor";

const json = {
    "key": "value",
    "another key": [
        1, 2, 3
    ],
    "number": 3.141592653589793
    "nulls are also encoded": null
};

// ArrayBuffer(51)
const encoded = CBOR.encode(json);

// { "key": "value", "another key": [1, 2, 3], "number": 3.14159265359, "nulls are also encoded": null}
const decoded = CBOR.decode(encoded);
console.log(decoded.key); // value
console.log(decoded.number); // 3.1415927410125732

You can also encode into a pre-allocated ArrayBuffer.

// Allocate a 64 byte buffer
const buffer = new ArrayBuffer(64);
// Encode the data into this buffer
const encoded = CBOR.encodeInto(data, buffer);

Notes

There are a few things from the specification which are currently unimplemented:

  • Byte strings
  • Tags, and the items they represent:
    • date/time, bignum/bigfloat as byte string, and others
  • 16-bit float (IEEE754 binary16)
  • Integers larger than 32 bit (BigInt)

These weren't required in my case, but if you need one or more of these features, submit an issue, and I'll implement it! :)

Keywords

FAQs

Package last updated on 26 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc