# @bensjoberg/fnv1a

> FNV-1a non-cryptographic hash function

Latest version **3.0.0** (published 2021-10-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bensjoberg/fnv1a
pnpm add @bensjoberg/fnv1a
yarn add @bensjoberg/fnv1a
bun add @bensjoberg/fnv1a
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2021-10-14 |
| First published | 2021-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Sindre Sorhus |
| Maintainers | bensjoberg |
| Keywords | fnv1a, fnv-1a, fnv1, fnv-1, fnv, algorithm, hash, hashing, string, function, fowler–noll–vo, fowler, noll, vo, unicode, bigint |

## Links

- npm: https://www.npmjs.com/package/@bensjoberg/fnv1a
- Repository: https://github.com/bensjoberg/fnv1a
- Homepage: https://github.com/bensjoberg/fnv1a#readme
- Issues: https://github.com/bensjoberg/fnv1a/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/@bensjoberg/fnv1a

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2021-10-14

## README

# Forked

Forked from https://github.com/sindresorhus/fnv1a and ported to CommonJS. (I really want to move to ESM, but my work has a couple projects that just aren't ready for it yet. 😢)

# fnv1a

> [FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash function

[FNV-1a has outstanding distribution and collisions are rare.](https://softwareengineering.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed/145633#145633)

FNV hashes are designed to be fast while maintaining a low collision rate. The FNV speed allows one to quickly hash lots of data while maintaining a reasonable collision rate. The high dispersion of the FNV hashes makes them well suited for hashing nearly identical strings such as URLs, hostnames, filenames, text, IP addresses, etc.

## Install

```
$ npm install @sindresorhus/fnv1a
```

## Usage

```js
import fnv1a from '@sindresorhus/fnv1a';

fnv1a('🦄🌈', {size: 32});
//=> 2868248295n

fnv1a('🦄🌈', {size: 128});
//=> 13487074350300261116944693128525960095n

Number(fnv1a('🦄🌈', {size: 32}));
//=> 2868248295
```

## API

### fnv1a(string, options?)

Returns the hash as a positive `BigInt`.

If you need it as a `number`, use `32` as `size` and wrap the return value in `Number(…)`.

#### options

Type: `object`

##### size

Type: `number`\
Values: `32 | 64 | 128 | 256 | 512 | 1024`\
Default: `32`

The bit size of the hash.

## Related

- [djb2a](https://github.com/sindresorhus/djb2a) - DJB2a non-cryptographic hash function
- [sdbm](https://github.com/sindresorhus/sdbm) - SDBM non-cryptographic hash function

---
_Source: https://npm.io/package/@bensjoberg/fnv1a · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
