@exodus/borc

中文文档
2.1.1发布于 2024/06/14MITCommonJS近 30 天下载 7.8万

以简明二进制对象表示(CBOR)数据格式(RFC7049)编码并解析数据.

中文使用文档
文档目录11 节
  1. 关于
  2. 安装
  3. 基准
  4. 示例
  5. API 密码
  6. 支持类型
  7. 自定义
  8. 编码自定义类型
  9. 编码自定义标记
  10. 解码自定义标记
  11. 许可证

曲线

Coverage Status Dependency Status Travis CI Circle CI

将所有的 JavaScript 对象同化到简明二进制对象表示 (CBOR) 数据格式中 (RFC7049 (法语)(中文(简体) ) 尽可能快。 。 。 .

关于

这个图书馆是超级棒的叉子 节点-cbor。它借用了许多界面,但会降低所有流和Aync处理,有利于最小的合成物并尽可能快.

安装

$ npm install --save borc

基准

开始

示例

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 密码

见 https://dcountaryquire.github.io/borc 页面存档备份,存于互联网档案馆 详情

同步编码和解码导出为 a leveldb 编码,作为 cbor.leveldb。 。 。 .

支持类型

下列类型支持编码:

  • 布尔
  • 数字(包括-0、NaN和±无限)
  • 字符串
  • 阵列, 设定( 编码为阵列)
  • 对象( 包括无效), 映射
  • 未定义
  • 缓冲
  • 日期,
  • 正则Exp
  • 尔曰. 網址
  • 大数

解码支持上述类型,包括以下CBOR标签编号:

标记生成类型
0 个日期
1个日期
2个大数
3个大数
页:1大数
页:1大数
第32条尔曰. 網址
35个正则Exp

自定义

Borc支持自定义标记以及自定义输入类型.

编码自定义类型

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')])

编码自定义标记

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

解码自定义标记

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

许可证

麻省理工学院

版本与发布记录

@exodus/borc 共发布 7 个版本,首次发布于 2019/07/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.1latest2024/06/142 年前
2.1.0-exodus42023/03/303 年前
2.1.0-exodus32023/03/303 年前
3.0.0-exodus.02021/06/215 年前
2.1.0-exodus22019/07/177 年前
2.1.0-exodus12019/07/177 年前

关于 @exodus/borc 的常见问题

@exodus/borc 是什么?

以简明二进制对象表示(CBOR)数据格式(RFC7049)编码并解析数据.

如何安装 @exodus/borc?

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

@exodus/borc 支持 TypeScript 吗?

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

@exodus/borc 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@exodus/borc 需要什么版本的 Node.js?

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

@exodus/borc 可以商用吗?

@exodus/borc 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/borc 的下载量有多少?

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

@exodus/borc 还在维护吗?

最新版本 2.1.1 发布于 2024/06/14(2 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/07/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。