$ cnpm install js-xxhash
Pure Javascript / Typescript Implementation of xxHash
This is an implementation for the XXH32 Algorithm.
A 64-bit version might come a bit later.
npm install --save js-xxhash
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
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));
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));
Copyright 2013 - present © cnpmjs.org | Home |