Socket
Socket
Sign inDemoInstall

js-xxhash

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    js-xxhash

Pure JS implementation of xxhash


Version published
Weekly downloads
42K
decreased by-9.18%
Maintainers
1
Install size
29.8 kB
Created
Weekly downloads
 

Changelog

Source

3.0.1 (2024-01-15)

Bug Fixes

  • Issue with CommonJS (#453) (4d6e121)

Readme

Source

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

Keywords

FAQs

Last updated on 15 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc