# @bonniernews/rolling-hash 中文文档

规范地址：https://npmcn.com/package/%40bonniernews/rolling-hash/

版本：2\.0\.0
npm 元数据更新时间：2026-08-26T12:06:56.608Z
中文译文更新时间：2026-11-08T11:04:15.571Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bonniernews/rolling-hash
原文对照：https://npmcn.com/package/%40bonniernews/rolling-hash/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：16.9 kB，18 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=20
- 运行依赖：0 个
- 首次发布：2023-10-10T08:22:32.574Z
- 最新版本发布：2026-06-02T13:40:45.633Z
- 近 30 天下载量：2942（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：4（近 12 个月 1 个）

## 中文简介

当吊销身份证时 你可能不希望它保持不变 **永远** 所以这个库通过滚动解决了这个问题.

## 安装

```sh
npm install @bonniernews/rolling-hash
```

也可以使用：`pnpm add @bonniernews/rolling-hash`、`yarn add @bonniernews/rolling-hash`、`bun add @bonniernews/rolling-hash`

## README

# 滚出大麻

当吊销身份证时 你可能不希望它保持不变 **永远** 所以这个库通过滚动解决了这个问题.

滚动在固定的日期间隔进行,然后给你新的ID来使用!

这个滚动散列库应该能够与各种加密库合作,并且仍然给出有效的滚动ID.

## 使用量

### 安装

`npm install @bonniernews/rolling-hash`

### 所需资源

节点.js20或更新.

### 运行

任何密码库都简单易用.

简单地输入给定的散列函数, 到 Base64 函数和 HexFunction 并取回一个滚动的 Hash .

带有自动加密库的示例 :

```javascript
import rollingHash from "@bonniernews/rolling-hash";
import crypto from "node:crypto";

async function hashFunction(str) {
  const arrayBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(str));

  return Array.from(new Uint8Array(arrayBuffer));
}

function toBase64Function(hash) {
  return Buffer.from(hash).toString("base64");
}

function toHexFunction(hash) {
  return hash.map((b) => b.toString(16).padStart(2, "0")).join("");
}

const rolledHash = await rollingHash("foobar", { hashFunction, toBase64Function, toHexFunction });

// use rolledHash as you want
```

使用同步加密库的例子 :

```javascript
import rollingHash from "@bonniernews/rolling-hash";
import cryptoJs from "crypto-js";

function hashFunction(str) {
  return cryptoJs.SHA256(str);
}

function toBase64Function(hash) {
  return hash.toString(cryptoJs.enc.Base64);
}

function toHexFunction(hash) {
  return hash.toString(cryptoJs.enc.Hex);
}

const rolledHash = rollingHash("foobar", { hashFunction, toBase64Function, toHexFunction });

// use rolledHash as you want
```

如果使用普通JS:

```javascript
const { default: rollingHash } = require("@bonniernews/rolling-hash");
```

## 免责声明

散列的滚动时间可能改变.

我们使用 Date 类来处理散列, 如果修改了它的话, 我们无法保证这将100%的时间工作 .

## 常见问题

### @bonniernews/rolling-hash 是什么？

当吊销身份证时 你可能不希望它保持不变 永远 所以这个库通过滚动解决了这个问题\.

### 如何安装 @bonniernews/rolling-hash？

在项目目录运行 npm install @bonniernews/rolling-hash，或使用 pnpm add / yarn add / bun add。

### @bonniernews/rolling-hash 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @bonniernews/rolling-hash 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @bonniernews/rolling-hash 需要什么版本的 Node\.js？

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

### @bonniernews/rolling-hash 可以商用吗？

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

### @bonniernews/rolling-hash 的下载量有多少？

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

### @bonniernews/rolling-hash 还在维护吗？

最新版本 2\.0\.0 发布于 2026/06/02（5 个月前）；至今共发布 4 个版本，其中过去 12 个月发布了 1 个；首次发布于 2023/10/10。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

