# borc

> Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).

Latest version **3.0.0** (published 2021-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install borc
pnpm add borc
yarn add borc
bun add borc
```

Provides the commands `cbor2diag`, `cbor2json`, `json2cbor`, `cbor2comment`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-04-27 |
| First published | 2016-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 7 |
| Unpacked size | 158 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 30 |
| Author | Friedel Ziegelmayer |
| Maintainers | daviddias, dignifiedquire, achingbrain |
| Keywords | coap, cbor, json, asm, asm.js |

## Links

- npm: https://www.npmjs.com/package/borc
- Repository: https://github.com/dignifiedquire/borc
- Homepage: https://github.com/dignifiedquire/borc.git
- Issues: https://github.com/dignifiedquire/borc/issues
- npm.io page: https://npm.io/package/borc

## Dependencies (7)

- [buffer](https://npm.io/package/buffer.md) ^6.0.3
- [ieee754](https://npm.io/package/ieee754.md) ^1.1.13
- [iso-url](https://npm.io/package/iso-url.md) ^1.1.5
- [commander](https://npm.io/package/commander.md) ^2.15.0
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.0.0
- [readable-stream](https://npm.io/package/readable-stream.md) ^3.6.0
- [json-text-sequence](https://npm.io/package/json-text-sequence.md) ~0.3.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.0 (latest) — 2021-04-27
- 2.1.2 — 2020-03-26
- 2.1.1 — 2019-07-10
- 2.1.0 — 2019-01-03
- 2.0.4 — 2018-10-18
- 2.0.3 — 2018-05-02
- 2.0.2 — 2017-01-29
- 2.0.1 — 2016-12-14
- 2.0.0 — 2016-12-11

## README

# borc

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/dignifiedquire/borc/badge.svg?branch=master)](https://coveralls.io/github/dignifiedquire/borc?branch=master)
[![Dependency Status](https://david-dm.org/dignifiedquire/borc.svg?style=flat-square)](https://david-dm.org/dignifiedquire/borc)
[![Travis CI](https://travis-ci.org/dignifiedquire/borc.svg?branch=master)](https://travis-ci.org/dignifiedquire/borc)


> Assimilate all your JavaScript objects into the Concise Binary Object Representation (CBOR) data format ([RFC7049](http://tools.ietf.org/html/rfc7049)) **as fast as possible**.


## About

This library is a fork of the awesome [node-cbor](https://github.com/hildjj/node-cbor). It borrows a lot of the interface, but drops all streaming and async processing in favor of a minimal syn api and being as fast as possible.


## Installation

```bash
$ npm install --save borc
```

## Benchmarks

TODO

## Example

```javascript
const cbor = require('borc')
const assert = require('assert')

const encoded = cbor.encode(true) // returns <Buffer f5>
const decoded = cbor.decodeFirst(encoded)
// decoded is the unpacked object
assert.ok(decoded === true)

// Use integers as keys
var m = new Map()
m.set(1, 2)
encoded = cbor.encode(m) // <Buffer a1 01 02>
```

## API

See https://dignifiedquire.github.io/borc for details

The sync encoding and decoding are exported as a
[leveldb encoding](https://github.com/Level/levelup#custom_encodings), as
`cbor.leveldb`.

## Supported types

The following types are supported for encoding:

* boolean
* number (including -0, NaN, and ±Infinity)
* string
* Array, Set (encoded as Array)
* Object (including null), Map
* undefined
* Buffer
* Date,
* RegExp
* url.URL
* [bignumber](https://github.com/MikeMcl/bignumber.js)

Decoding supports the above types, including the following CBOR tag numbers:

| Tag | Generated Type |
|-----|----------------|
| 0   | Date           |
| 1   | Date           |
| 2   | bignumber      |
| 3   | bignumber      |
| 4   | bignumber      |
| 5   | bignumber      |
| 32  | url.URL        |
| 35  | RegExp         |


## Customizations

Borc supports custom tags as well as custom input types.

### Encode Custom Types

```js
class MyType {
  constructor (val) {
    this.val = val
  }

  // Gets called when encoding this object
  // gen - instance of the encoder
  // obj - the object being encoded
  //
  // should return true on success and false otherwise
  encodeCBOR (gen) {
    return gen.pushAny('mytype:' + this.val)
  }
}

cbor.encode([new MyType('hello')])
```

### Encode Custom Tags

```js
cbor.encode([new cbor.Tagged(42, 'hello')])
```

### Decode Custom Tags

```js
const decoder = new cbor.Decoder({
  tags: {
    42: (val) => val + ' world'
  }
})
```

## License

MIT

---
_Source: https://npm.io/package/borc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
