# js-xxhash

> Pure JS implementation of xxhash

Latest version **5.0.1** (published 2025-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-xxhash
pnpm add js-xxhash
yarn add js-xxhash
bun add js-xxhash
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2025-11-19 |
| First published | 2019-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.0.0 |
| Dependencies | 0 |
| Unpacked size | 31.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 49 |
| Author | Jason Dent |
| Maintainers | jason-dent |
| Keywords | xxhash, javascript, typescript |

## Links

- npm: https://www.npmjs.com/package/js-xxhash
- Repository: https://github.com/Jason3S/xxhash
- Homepage: https://github.com/Jason3S/xxhash#readme
- Issues: https://github.com/Jason3S/xxhash/issues
- npm.io page: https://npm.io/package/js-xxhash

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2025-11-19
- 4.0.0 — 2024-05-28
- 3.0.1 — 2024-01-15
- 3.0.0 — 2023-10-16
- 2.0.0 — 2022-10-18
- 1.0.4 — 2019-07-28
- 1.0.3 — 2019-07-28
- 1.0.2 — 2019-07-28
- 1.0.1 — 2019-02-02
- 1.0.0 — 2019-01-22

## README

# js-xxHash

Pure Javascript / Typescript Implementation of [xxHash](http://cyan4973.github.io/xxHash/)

This is an implementation for the
[XXH32 Algorithm](https://github.com/Cyan4973/xxHash/blob/dev/doc/xxhash_spec.md#xxh32-algorithm-description)
A 64-bit version might come a bit later.

## Why another version

- I needed a fast simple hash for short to medium sized strings.
- It needed to be pure JS.

## Installation

```
npm install --save js-xxhash
```

## Usage

### Pure JS

Internally it uses [TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) to convert strings to a UTF-8 `Uint8Array`s.

```typescript
import { xxHash32 } from 'js-xxhash';

let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(str, seed);
console.log(hashNum.toString(16));
```

Expected:

```
af7fd356
```

### Node JS

```typescript
import { xxHash32 } from 'js-xxhash';

let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(str, seed);
console.log(hashNum.toString(16));
```

### Browser

```typescript
// Using a bundler
import { xxHash32 } from 'js-xxhash';
// Using a CDN like jsDelivr
import { xxHash32 } from 'https://cdn.jsdelivr.net/npm/js-xxhash@{version}/index.mjs';

let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(str, seed);
console.log(hashNum.toString(16));
```

# Performance

To evaluate performance this package was compared to:

- [xxhashjs](https://www.npmjs.com/package/xxhashjs)
- [xxhash-wasm](https://www.npmjs.com/package/xxhash-wasm)

One average a lorem-ipsum "word" is between 5 and 6 characters.

## Performance for Strings

```
Running Perf Suite: xxhash-string-words-10
Evaluate xxhash performance with a string of 10 words.
✔ js-xxhash string       731_148.14 ops/sec
✔ xxhashjs string        432_753.87 ops/sec
✔ xxhash-wasm string   3_381_907.91 ops/sec

Running Perf Suite: xxhash-string-words-100
Evaluate xxhash performance with a string of 100 words.
✔ js-xxhash string       420_458.19 ops/sec
✔ xxhashjs string        124_443.56 ops/sec
✔ xxhash-wasm string   2_289_457.63 ops/sec

Running Perf Suite: xxhash-string-words-1000
Evaluate xxhash performance with a string of 1000 words.
✔ js-xxhash string        74_861.33 ops/sec
✔ xxhashjs string         16_656.57 ops/sec
✔ xxhash-wasm string     729_339.20 ops/sec

Running Perf Suite: xxhash-string-words-10000
Evaluate xxhash performance with a string of 10000 words.
✔ js-xxhash string         6_293.40 ops/sec
✔ xxhashjs string            551.90 ops/sec
✔ xxhash-wasm string      90_170.30 ops/sec

Running Perf Suite: xxhash-string-words-100000
Evaluate xxhash performance with a string of 100000 words.
✔ js-xxhash string           709.30 ops/sec
✔ xxhashjs string             40.05 ops/sec
✔ xxhash-wasm string       8_093.17 ops/sec
```

### Performance with a Uint8Array Buffer

```
Running Perf Suite: xxhash-buffer-words-10
Evaluate xxhash performance with a buffer containing a string of 10 words.
✔ js-xxhash buffer       2_859_850.03 ops/sec
✔ xxhashjs buffer          699_053.22 ops/sec
✔ xxhash-wasm buffer     3_657_504.67 ops/sec

Running Perf Suite: xxhash-buffer-words-100
Evaluate xxhash performance with a buffer containing a string of 100 words.
✔ js-xxhash buffer         800_609.77 ops/sec
✔ xxhashjs buffer          402_424.91 ops/sec
✔ xxhash-wasm buffer     2_569_294.66 ops/sec

Running Perf Suite: xxhash-buffer-words-1000
Evaluate xxhash performance with a buffer containing a string of 1000 words.
✔ js-xxhash buffer         79_925.04 ops/sec
✔ xxhashjs buffer          55_568.13 ops/sec
✔ xxhash-wasm buffer      753_856.33 ops/sec

Running Perf Suite: xxhash-buffer-words-10000
Evaluate xxhash performance with a buffer containing a string of 10000 words.
✔ js-xxhash buffer          8_152.57 ops/sec
✔ xxhashjs buffer           6_046.82 ops/sec
✔ xxhash-wasm buffer      104_463.50 ops/sec

Running Perf Suite: xxhash-buffer-words-100000
Evaluate xxhash performance with a buffer containing a string of 100000 words.
✔ js-xxhash buffer            458.33 ops/sec
✔ xxhashjs buffer             602.90 ops/sec
✔ xxhash-wasm buffer        9_835.61 ops/sec
```

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