Skip to content
Pure JS Implementation of xxhash
TypeScript
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
docs
src
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
_config.yml
appveyor.yml
package-lock.json
package.json
test.txt
tsconfig.json
tslint.json

README.md

xxHash

Pure Javascript / Typescript Implementation of xxHash

This is an implementation for the XXH32 Algorithm.

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

Uses an internal JS conversion of strings to a UTF-8 Uint8Array. For higher performance consider using dedicated converters in the examples for Node and Browser below.

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

import {xxHash32} from 'js-xxhash';

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

Browser

In a browser, you need to use a function or library to create a Uint8Array

Using Browserify you can use it like this:

import {xxHash32} from 'js-xxhash';

let textEncoder = new TextEncoder(); // Note TextEncoder is experimental
let seed = 0;
let str = 'My text to hash 😊';
let hashNum = xxHash32(textEncoder.encode(str), seed);
console.log(hashNum.toString(16));
You can’t perform that action at this time.