js-xxhash
Pure JS implementation of xxhash
Last updated 7 years ago by jason-dent .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install js-xxhash 
SYNC missed versions from official npm registry.

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));

Current Tags

  • 1.0.4                                ...           latest (7 years ago)

5 Versions

  • 1.0.4                                ...           7 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (13)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |