@adviser/ts-xxhash

中文文档
1.0.2发布于 2025/09/10MITTypeScriptESM + CJS零依赖近 30 天下载 2.5万

xxHash in Typescript

原始使用文档
文档目录6 节
  1. Synopsis
  2. Installation
  3. Examples
  4. Usage
  5. Methods
  6. License

Javascript implementation of xxHash

Synopsis

xxHash is a very fast hashing algorithm (see the details here). xxhashjs is a Javascript implementation of it, written in 100% Javascript. Although not as fast as the C version, it does perform pretty well given the current Javascript limitations in handling unsigned 32 bits integers.

Installation

In nodejs:

npm install xxhashjs

In the browser, include the following, and access the constructor with XXH:

<script src="/your/path/to/xxhash.js"></script>

Examples

  • In one step:
var h = XXH.h32("abcd", 0xabcd).toString(16); // seed = 0xABCD

0xCDA8FAE4

  • In several steps (useful in conjunction of NodeJS streams):
var H = XXH.h32(0xabcd); // seed = 0xABCD
var h = H.update("abcd").digest().toString(16);

0xCDA8FAE4

  • More examples in the examples directory:
    • Compute xxHash from a file data
    • Use xxHashjs in the browser

Usage

  • XXH makes 2 functions available for 32 bits XXH and 64 bits XXH respectively, with the same signature:

    • XXH.h32
    • XXH.h64
  • In one step: XXH.h32(<data>, <seed>) The data can either be a string, an ArrayBuffer or a NodeJS Buffer object. The seed can either be a number or a UINT32 object.

  • In several steps: * instantiate a new XXH object H: XXH.h32(<seed>) or XXH.h32() The seed can be set later on with the init method

    * add data to the hash calculation:
    

    H.update(<data>)

    * finish the calculations:
    

    H.digest()

The object returned can be converted to a string with toString(<radix>) or a number toNumber(). Once digest() has been called, the object can be reused. The same seed will be used or it can be changed with init(<seed>).

Methods

  • XXH.h32()

    • .init(<seed>) Initialize the XXH object with the given seed. The seed can either be a number or a UINT32 object.
    • .update(<data>) Add data for hashing. The data can either be a string, an ArrayBuffer or a NodeJS Buffer object. * digest() (UINT32) Finalize the hash calculations and returns an UINT32 object. The hash value can be retrieved with toString().
  • XXH.h64()

    • .init(<seed>) Initialize the XXH object with the given seed. The seed can either be a number or a UINT64 object.
    • .update(<data>) Add data for hashing. The data can either be a string, an ArrayBuffer or a NodeJS Buffer object.
    • .digest() (UINT64) Finalize the hash calculations and returns an UINT64 object. The hash value can be retrieved with toString().

License

MIT

版本与发布记录

@adviser/ts-xxhash 共发布 3 个版本,首次发布于 2025/09/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.2latest2025/09/101.2 年前
1.0.12025/09/101.2 年前
1.0.02025/09/101.2 年前

关于 @adviser/ts-xxhash 的常见问题

@adviser/ts-xxhash 是什么?

xxHash in Typescript

如何安装 @adviser/ts-xxhash?

在项目目录运行 npm install @adviser/ts-xxhash,或使用 pnpm add / yarn add / bun add。

@adviser/ts-xxhash 支持 TypeScript 吗?

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

@adviser/ts-xxhash 支持 ESM 还是 CommonJS?

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

@adviser/ts-xxhash 可以商用吗?

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

@adviser/ts-xxhash 的下载量有多少?

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

@adviser/ts-xxhash 还在维护吗?

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