# @enonic/fnv-plus 中文文档

规范地址：https://npmcn.com/package/%40enonic/fnv-plus/

版本：1\.3\.0
npm 元数据更新时间：2026-09-04T14:13:27.397Z
中文译文更新时间：2026-11-13T17:49:47.830Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40enonic/fnv-plus
原文对照：https://npmcn.com/package/%40enonic/fnv-plus/?lang=original
项目主页：https://github.com/tjwebb/fnv-plus#readme
源码仓库：https://github.com/tjwebb/fnv-plus

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

- 包体积（解压后）：188 kB，3 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2019-06-17T15:14:07.191Z
- 最新版本发布：2019-06-17T15:14:07.539Z
- 近 30 天下载量：101862（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

Javascript FNV-1a Hashing Algorithm上至1024位,高度优化了32位和52位的实现.

## 安装

```sh
npm install @enonic/fnv-plus
```

也可以使用：`pnpm add @enonic/fnv-plus`、`yarn add @enonic/fnv-plus`、`bun add @enonic/fnv-plus`

## README

# fnv- plus (日语)

[![NPM version](https://img.shields.io/npm/v/fnv-plus.svg?style=flat-square)](https://npmjs.org/package/fnv-plus) [![Build status](https://img.shields.io/travis/tjwebb/fnv-plus.svg?style=flat-square)](https://travis-ci.org/tjwebb/fnv-plus)

Javascript FNV-1a Hashing Algorithm上至1024位,高度优化了32位和52位的实现.

## 概念

FNV-1a散列算法,常被简单地称为"fnv",会分散散列 整个正位散列空间的分散度非常高 快点.

使用此模块生成 Javascript 唯一的散列/ 检查和和值 字符串或对象. **说明:** FNV-1a算法甚至不适宜于 密码伪随机生成器,不应用于保护任何 任何原因都一样 它的设计为 _特性_没有 _随机性_。 。 。 .

##### 为什么 **fnv- plus (日语)**? 吗?

-   这是 **快点** 可供节点Js使用的FNV执行 [脱口而出](https://github.com/desudesutalk)) (中文(简体) ). 见 [基准](https://github.com/tjwebb/fnv-plus/tree/master/benchmark)。 。 。 .
-   它是唯一能够为大于32位的密钥空间生成fnv hashes的npm模块.
-   `fnv-plus` 已经测试过了 许多其他fnv的应用没有提供单位测试来证明它们的工作和表现.
-   `fnv-plus` 执行一个52bit版本的FNV-1a,它提供了更大的散列空间,同时仍然使用Javascript的53位整数空间.

##### 1.3.x 新设

-   没有依附关系!
-   [快速变换](https://github.com/tjwebb/fnv-plus#fast-variants) 优化速度.

##### 1.2.x中新建

-   您可以轻松定义自定义种子 .
-   页:1 `hash()` 函数现在可以将任意 Javascript 对象作为输入.
-   默认位长改为 **第52条**

## 安装

```sh
$ npm install fnv-plus --save
```

## 使用量

```
var fnv = require('fnv-plus'),
    astring = 'hello world',
    ahash52 = fnv.hash(astring),        // 52-bit hash by default
    ahash64 = fnv.hash(astring, 64);    // 64-bit hash specified

console.log(ahash52.hex() == 'a65e7023cd59e');    //true
console.log(ahash52.str() == 'stglysbf6m');       //true
console.log(ahash52.dec() == '2926792616498590'); //true

console.log(ahash64.hex() == '779a65e7023cd2e7');     //true
console.log(ahash64.str() == '1th7cxzlyc0dj');        //true
console.log(ahash64.dec() == '8618312879776256743');  //true

// fast variants
console.log(fnv.fast1a32hex(astring) == 'd58b3fa7');      //true
console.log(fnv.fast1a52hex(astring) == 'a65e7023cd59e'); //true

fnv.seed('foobar testseed');
console.log(fnv.hash(astring, 64).hex() == ahash64.hex()); // false
// ^^ because the default seed is not 'foobar testseed'
```

## API 密码

#### `fnv.hash(string, bitlength)`

-   使用给定比特长度( 52 为默认值) 将字符串挂起
-   返回 a `FnvHash` 对象

#### `fnv.seed(string)`

-   种子算法生成不同的值. 使用同样的值 不同的种子很可能会产生不同的结果。 尽可能 你的种子可以是随机的, 它可以作为随机的来源,但 不过 _没有_ 替换密码式PRG( pseudo-random) 发电机).
-   默认种子是 `chongo <Landon Curt Noll> /\>./\\`

#### `fnv.useUTF8(bool)`

-   UTF-8 对散列函数的认识
-   默认为 `false`

#### `FnvHash.str()`

返回作为 ASCii 字符串的散列值

#### `FnvHash.hex()`

以十六进制字符串返回散列值

#### `FnvHash.dec()`

以小数字符串返回散列值

### 快速变体

这个功能运行得更快,因为它们没有 _自由管理_ (见 [基准](https://npmcn.com/package/%40enonic/fnv-plus/benchmark/README.md) 以获得更多信息。 他们总是计算1a 版本的散列并总是使用默认种子. 直接返回散列值 (无) `FnvHash` 对象).

#### `fnv.fast1a32(string)`

-   计算 FNV-1a 32 位散列
-   返回输入

#### `fnv.fast1a32hex(string)`

-   计算 FNV-1a 32 位散列
-   返回十六进制字符串

#### `fnv.fast1a52(string)`

-   计算 FNV-1a 52 位散列
-   返回输入

#### `fnv.fast1a52hex(string)`

-   计算 FNV-1a 52 位散列
-   返回十六进制字符串

#### `fnv.fast1a64(string)`

-   计算 FNV-1a 64 位散列
-   返回十六进制字符串

#### `fnv.fast1a32utf(string)`

-   计算 FNV-1a 32 位散列
-   处理 UTF-8 字符串
-   返回输入

#### `fnv.fast1a32hexutf(string)`

-   计算 FNV-1a 32 位散列
-   处理 UTF-8 字符串
-   返回十六进制字符串

#### `fnv.fast1a52utf(string)`

-   计算 FNV-1a 52 位散列
-   处理 UTF-8 字符串
-   返回输入

#### `fnv.fast1a52hexutf(string)`

-   计算 FNV-1a 52 位散列
-   处理 UTF-8 字符串
-   返回十六进制字符串

#### `fnv.fast1a64utf(string)`

-   计算 FNV-1a 64 位散列
-   处理 UTF-8 字符串
-   返回十六进制字符串

## 许可证

麻省理工学院

## 常见问题

### @enonic/fnv-plus 是什么？

Javascript FNV-1a Hashing Algorithm上至1024位,高度优化了32位和52位的实现\.

### 如何安装 @enonic/fnv-plus？

在项目目录运行 npm install @enonic/fnv-plus，或使用 pnpm add / yarn add / bun add。

### @enonic/fnv-plus 支持 TypeScript 吗？

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

### @enonic/fnv-plus 支持 ESM 还是 CommonJS？

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

### @enonic/fnv-plus 可以商用吗？

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

### @enonic/fnv-plus 的下载量有多少？

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

### @enonic/fnv-plus 还在维护吗？

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

