6.0.3 • Published 5 months ago

@digitalbazaar/cborld v6.0.3

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
5 months ago

JavaScript CBOR-LD Processor

A JavaScript CBOR-LD Process for Web browsers and Node.js apps.

Table of Contents

Background

This library provides a CBOR-LD Processor for Web browsers and Node.js applications.

Install

  • Browsers and Node.js 14+ are supported.

NPM

npm install @digitalbazaar/cborld

Git

To install locally (for development):

git clone https://github.com/digitalbazaar/cborld.git
cd cborld
npm install

Usage

This library provides two primary functions for encoding and decoding CBOR-LD data.

Encode to CBOR-LD

To encode a JSON-LD document as CBOR-LD:

import {encode, documentLoader} from '@digitalbazaar/cborld';

const jsonldDocument = {
  '@context': 'https://www.w3.org/ns/activitystreams',
  type: 'Note',
  summary: 'CBOR-LD',
  content: 'CBOR-LD is awesome!'
};

// encode a JSON-LD Javascript object into CBOR-LD bytes
const cborldBytes = await encode({jsonldDocument, documentLoader});

To decode a CBOR-LD document to JSON-LD:

import {decode, documentLoader} from '@digitalbazaar/cborld';

// get the CBOR-LD bytes
const cborldBytes = await fs.promises.readFile('out.cborld');

// decode the CBOR-LD bytes into a Javascript object
const jsonldDocument = await cborld.decode({cborldBytes, documentLoader});

API

Functions

Typedefs

encode(options) ⇒ Promise<Uint8Array>

Encodes a given JSON-LD document into a CBOR-LD byte array.

Kind: global function Returns: Uint8Array - - The encoded CBOR-LD bytes.

decode(options) ⇒ Promise<object>

Decodes a CBOR-LD byte array into a JSON-LD document.

Kind: global function Returns: object - - The decoded JSON-LD Document.

diagnosticFunction : function

A diagnostic function that is called with diagnostic information. Typically set to console.log when debugging.

Kind: global typedef

documentLoaderFunction ⇒ string

Fetches a resource given a URL and returns it as a string.

Kind: global typedef Returns: string - The resource associated with the URL as a string.

Examples:

TBD

Contribute

Please follow the existing code style.

PRs accepted.

If editing the README, please conform to the standard-readme specification.

Commercial Support

Commercial support for this library is available upon request from Digital Bazaar: support@digitalbazaar.com

License

BSD-3-Clause © Digital Bazaar

6.0.3

5 months ago

6.0.1

6 months ago

6.0.0

6 months ago

6.0.2

6 months ago

5.2.0

6 months ago

5.1.0

6 months ago

5.0.0

2 years ago

4.4.0

2 years ago

4.3.0

3 years ago

4.1.0

3 years ago

4.2.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

2.2.0

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago