Giter Site home page Giter Site logo

jkrhb / cborld Goto Github PK

View Code? Open in Web Editor NEW

This project forked from digitalbazaar/cborld

0.0 1.0 0.0 234 KB

A Javascript CBOR-LD processor for web browsers and Node.js apps.

Home Page: https://digitalbazaar.github.io/cbor-ld-spec/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

cborld's Introduction

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

encode(options)Uint8Array

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

decode(options)object

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

Typedefs

diagnosticFunction : function

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

documentLoaderFunctionstring

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

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.

Param Type Description
options object

The options to use when encoding to CBOR-LD.

options.jsonldDocument object

The JSON-LD Document to convert to CBOR-LD bytes.

options.documentLoader documentLoaderFunction

The document loader to use when resolving JSON-LD Context URLs.

[options.appContextMap] Map

A map of JSON-LD Context URLs and their encoded CBOR-LD values (must be values greater than 32767 (0x7FFF)).

[options.appTermMap] Map

A map of JSON-LD terms and their associated CBOR-LD term codecs.

[options.diagnose] diagnosticFunction

A function that, if provided, is called with diagnostic information.

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.

Param Type Description
options object

The options to use when decoding CBOR-LD.

options.cborldBytes Uint8Array

The encoded CBOR-LD bytes to decode.

options.documentLoader function

The document loader to use when resolving JSON-LD Context URLs.

[options.appContextMap] Map

A map of JSON-LD Context URLs and their associated CBOR-LD values. The values must be greater than 32767 (0x7FFF)).

[options.appTermMap] Map

A map of JSON-LD terms and their associated CBOR-LD term codecs.

[options.diagnose] diagnosticFunction

A function that, if provided, is called with diagnostic information.

diagnosticFunction : function

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

Kind: global typedef

ParamTypeDescription
messagestring

The diagnostic message.

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.

Param Type Description
url string

The URL to retrieve.

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: [email protected]

License

BSD-3-Clause © Digital Bazaar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.