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 - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

dist/common/view.d.ts

31

package.json
{
"name": "@jprochazk/cbor",
"version": "0.2.5",
"version": "0.3.0",
"description": "Partial implementation of RFC 7049 (CBOR)",
"keywords": [
"cbor",
"sax"
],
"main": "build/index.js",
"author": "Jan Procházka",
"license": "MIT",
"homepage": "https://github.com/jprochazk/cbor",
"repository": {

@@ -14,12 +12,21 @@ "type": "git",

},
"author": "Jan Procházka",
"license": "MIT",
"bugs": {
"url": "https://github.com/jprochazk/cbor/issues"
},
"keywords": [
"cbor",
"sax"
],
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"browser": "dist/index.umd.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "jest",
"build": "webpack --config webpack.prod.js"
"build": "rollup -c",
"prepublish": "npm run build && npm run test"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@types/jest": "^26.0.3",

@@ -30,6 +37,8 @@ "@typescript-eslint/eslint-plugin": "^3.2.0",

"jest": "^25.2.1",
"rollup": "^2.23.1",
"rollup-plugin-typescript2": "^0.27.2",
"ts-jest": "^25.5.0",
"tslib": "^2.0.1",
"typescript": "^3.9.4"
},
"homepage": "https://github.com/jprochazk/cbor"
}
}

@@ -10,12 +10,12 @@ # cbor

This library is meant for use in the browser, but will also work in Node.
```
> npm install @jprochazk/cbor
> npm install cbor@npm:jprochazk/cbor
```
The above command will install the library under the `cbor` alias.
The API is very simple:
```js
import CBOR from "@jprochazk/cbor";
import CBOR from "cbor";

@@ -31,15 +31,10 @@ const json = {

// 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.
You can also encode into a pre-allocated buffer.
```js
// Allocate a 64 byte buffer
const buffer = new ArrayBuffer(64);
// Allocate a 4KiB buffer
const buffer = new ArrayBuffer(4096);
// Encode the data into this buffer

@@ -49,4 +44,19 @@ const encoded = CBOR.encodeInto(data, buffer);

### Benchmarks
Speed was one of my main concerns when writing this library. The source code of the benchmark is available [here](https://github.com/jprochazk/cbor-benchmark). Here are the results:
| CPU | CBOR.encode | CBOR.encodeInto | CBOR.decode |
| :------- | :---------- | :-------------- | :---------- |
| i5-8600K | 0.6555 ms | 0.5743 ms | 1.1312 ms |
The JSON object used is ~13KB decoded, ~6KB encoded. This means ~13MB/s decoding speed and ~10MB/s encoding speed.
You can squeeze out a bit more performance if you use `CBOR.encodeInto` with a sufficiently large buffer. the `CBOR.encode` default is 1024 bytes, which should be enough for the vast majority of uses, but if you ever find yourself using more than that, utilize `CBOR.encodeInto`.
### Notes
This library is meant for use in the browser. Node support is in the works.
There are a few things from the specification which are currently unimplemented:

@@ -60,2 +70,2 @@

These weren't required in my case, but if you need one or more of these features, submit an [issue](https://github.com/jprochazk/cbor/issues), and I'll implement it! :)
These weren't required in my case, but they're trivial additions to the existing parser/writer logic. If you need one or more of these features, submit an [issue](https://github.com/jprochazk/cbor/issues).
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