@bonniernews/rolling-hash

中文文档
2.0.0发布于 2026/06/02MITTypeScriptESM + CJS零依赖近 30 天下载 2942

When hashing an ID you might not want it to stay the same forever so this library solves that by making it rolling.

原始使用文档
文档目录5 节
  1. Usage
  2. Installing
  3. Requirements
  4. running
  5. Disclaimer

Rolling hash

When hashing an ID you might not want it to stay the same forever so this library solves that by making it rolling.

The rolling occurs at a fixed date interval and in turn gives you a new fresh ID to use!

This rolling hash library is supposed to be able to work with all kinds of encryption libraries and still give a valid rolling ID.

Usage

Installing

npm install @bonniernews/rolling-hash

Requirements

Node.js 20 or newer.

running

The code is simple to use with any crypto Library.

Simply input the given hashFunction, toBase64Function and toHexFunction and retrieve a rolledHash.

example with an async crypto library:

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

example with a sync crypto library:

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

if using commonJS:

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

Disclaimer

The interval at which the rolling of the hash is performed may change.

We use the Date class to handle the hash, if this is modified in anyway we cannot guarantee that this will work a 100% of the time.

版本与发布记录

@bonniernews/rolling-hash 共发布 4 个版本,首次发布于 2023/10/10;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.0latest2026/06/025 个月前
1.0.22023/10/103 年前
1.0.12023/10/103 年前
1.0.02023/10/103 年前

关于 @bonniernews/rolling-hash 的常见问题

@bonniernews/rolling-hash 是什么?

When hashing an ID you might not want it to stay the same forever so this library solves that by making it rolling.

如何安装 @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 和提交记录判断。