@digitalbazaar/cborld

中文文档
8.1.0发布于 2026/04/29BSD-3-ClauseES Module近 30 天下载 1万

A CBOR-LD encoder/decoder for Javascript.

原始使用文档
文档目录17 节
  1. Table of Contents
  2. Background
  3. Install
  4. NPM
  5. Git
  6. Usage
  7. Encode to CBOR-LD
  8. API
  9. Functions
  10. Typedefs
  11. encode(options) ⇒ Promise<Uint8Array>
  12. decode(options) ⇒ Promise<object>
  13. diagnosticFunction : function
  14. documentLoaderFunction ⇒ string
  15. Contribute
  16. Commercial Support
  17. License

JavaScript CBOR-LD Processor

Build Status Coverage Status

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

This software requires and supports maintained recent versions of Node.js and browsers. Updates may remove support for older unmaintained platform versions. Please use dependency version lock files and testing to ensure compatibility with this software.

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} 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
// Note: user must provide their own JSON-LD `documentLoader`
const cborldBytes = await encode({
  jsonldDocument,
  documentLoader,
  // use standard compression (set to `0` to use no compression)
  registryEntryId: 1
});

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

import {decode} 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
// Note: user must provide their own JSON-LD `documentLoader`
const jsonldDocument = await cborld.decode({cborldBytes, documentLoader});

API

NOTE: Please check encode.js and decode.js for the latest API options.

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.

documentLoaderFunction ⇒ string

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

版本与发布记录

@digitalbazaar/cborld 共发布 33 个版本,首次发布于 2020/07/24;过去 12 个月发布了 1 个版本。

版本发布日期距今
8.1.0latest2026/04/296 个月前
8.0.22025/09/061.2 年前
8.0.12025/05/221.5 年前
8.0.02025/04/251.5 年前
7.3.02025/04/241.5 年前
7.2.12025/04/151.6 年前

关于 @digitalbazaar/cborld 的常见问题

@digitalbazaar/cborld 是什么?

A CBOR-LD encoder/decoder for Javascript.

如何安装 @digitalbazaar/cborld?

在项目目录运行 npm install @digitalbazaar/cborld,或使用 pnpm add / yarn add / bun add。

@digitalbazaar/cborld 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/digitalbazaar__cborld 是否存在。

@digitalbazaar/cborld 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@digitalbazaar/cborld 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@digitalbazaar/cborld 可以商用吗?

@digitalbazaar/cborld 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@digitalbazaar/cborld 的下载量有多少?

根据 npm 官方下载统计,@digitalbazaar/cborld 在 2026/10/12 – 2026/11/10 这 30 天内被下载 10,489 次,日均约 350 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@digitalbazaar/cborld 还在维护吗?

最新版本 8.1.0 发布于 2026/04/29(6 个月前);至今共发布 33 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/07/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。