JavaScript CMOR- LD 处理器
一个用于Web浏览器和Node.js应用程序的JavaScript CBOR-LD进程.
目录
背景情况
此库为 Web 浏览器和 Node.js 提供 CBOR- LD 处理器 应用.
安装
该软件需要并支持维持的最近版本的Node.js和 浏览器. 更新可能会去除对旧的未维护的平台版本的支持. 请使用依赖性版本锁文件和测试以确保兼容性 与这个软件.
国家预防机制
npm install @digitalbazaar/cborld
图形
在当地安装(用于开发):
git clone https://github.com/digitalbazaar/cborld.git
cd cborld
npm install
使用量
此库提供了编码和解码的两种主要功能 CBOR-LD数据.
编码为 CBOR- LD
要将 JSON- LD 文档编码为 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
});
要将 CBOR-LD 文档解码为 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 密码
页:1: 请检查 encode.js 财务报告和审定财务报表 decode.js 用于最新的 API 选项.
职能
- 编码( 选项) ⇒
Uint8Array -
将给定的 JSON-LD 文档编码为 CBOR-LD 字节数组.
- 解码( 选项) ⇒
object -
将 CBOR-LD 字节数组解码为 JSON-LD 文档.
类型防御
- 诊断功能 数字 :
function -
诊断功能,使用 诊断信息。 通常设置为
console.log何时 调试中. - 文档 Loader 函数 ⇒
string -
获取给定的资源并返回 URL 作为弦.
编码( 选项) qq Promise<Uint8Array>
将给定的 JSON-LD 文档编码为 CBOR-LD 字节数组.
仁爱:全球职能
回返数字 : Uint8Array - 编码的CBOR-LD字节.
| 参数 | 类型 | 说明 |
|---|---|---|
| 选项 | object |
这个 选项,用于编码到 CBOR-LD 时. |
| 选项.jsonldDocument | object |
JSON -LD(日语) 要转换为 CBOR- LD 字节的文档 . |
| 选项。文档读取器 | documentLoaderFunction |
在解决 JSON- LD 上下文 URL 时使用的文档加载器 . |
| [选项.appContextMap] | Map |
JSON- LD 上下文 URL 及其编码的 CBOR- LD 值的映射 (数值必须大于32767 (0x7FFF)). |
| [选项.apptermMap] (英语) | Map |
JSON-LD术语及其相关 CBOR-LD名词代码. |
| [选项.诊断] | diagnosticFunction |
如果提供这种功能,则称为诊断 资料. |
解码( 选项) qq Promise<object>
将 CBOR-LD 字节数组解码为 JSON-LD 文档.
仁爱:全球职能
回返数字 : object - 解码的JSON -LD文档.
| 参数 | 类型 | 说明 |
|---|---|---|
| 选项 | object |
解码 CBOR- LD 时使用的选项 . |
| 选项.cborldBytes | Uint8Array |
编码的 CBOR- LD 字节为 解码. |
| 选项。文档读取器 | function |
文档加载器 解决 JSON- LD 上下文 URL . |
| [选项.appContextMap] | Map |
JSON- LD 上下文 URL 和 它们相关的 CBOR-LD 值。 数值必须大于 32767 (0x7FFF) (英语). |
| [选项.apptermMap] (英语) | Map |
JSON-LD术语和 他们相关的 CBOR-LD 术语代码. |
| [选项.诊断] | diagnosticFunction |
一个函数,如果 提供诊断信息. |
诊断功能 : function
诊断功能,与诊断信息相呼应. 一般来说
设置为 console.log 当调试时.
仁爱: 全局类型def
| 参数 | 类型 | 说明 |
|---|---|---|
| 消息 | string | 诊断信息. |
文档 Loader 函数 {} string
获取一个给定的 URL 资源并将它作为字符串返回 .
仁爱: 全局类型def
回返数字 : string - 与 URL 作为字符串相关的资源 .
| 参数 | 类型 | 说明 |
|---|---|---|
| url 密码 | string |
要检索的 URL . |
实例:
TBD
贡献
请遵循现有的代码样式 .
公关接受.
如果编辑 README, 请遵守 标准读取 规格.
商业支助
该图书馆的商务支助可应下列请求提供: 数字集市: 支持@ digitalbazaar.com
许可证
BSD-3- 标签 数字集市