npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fnv-plus

v1.3.1

Published

Javascript FNV-1a Hashing Algorithm up to 1024 bits, with highly optimized 32bit and 52bit implementations.

Downloads

698,278

Readme

fnv-plus

NPM version Build status

Javascript FNV-1a Hashing Algorithm up to 1024 bits, with highly optimized 32bit and 52bit implementations.

Concept

The FNV-1a hash algorithm, often simply called "fnv", disperses hashes throughout the n-bit hash space with very good dispersion and is very fast.

Use this module to generate unique hash/checksum values for Javascript strings or objects. Note: The FNV-1a algorithm is not even remotely suitable as a cryptographic pseudo-random generator, and should not be used to secure any thing for any reason. It is designed for uniqueness, not randomness.

Why fnv-plus?
  • It is the fastest FNV implementation available for Node.js (thanks desudesutalk). See Benchmarks.
  • It is the only npm module that is capable of generating fnv hashes for keyspaces larger than 32 bits.
  • fnv-plus is well-tested. Many other fnv implementations offer no unit tests to prove they work and are performant.
  • fnv-plus implements a 52bit version of FNV-1a which provides a larger hash space while still making use of Javascript's 53-bit integer space.
New in 1.3.x
New in 1.2.x
  • You can easily define custom seeds.
  • the hash() function can now take arbitrary Javascript objects as input.
  • changed default bitlength to 52

Install

$ npm install fnv-plus --save

Usage

var fnv = require('fnv-plus'),
    astring = 'hello world',
    ahash52 = fnv.hash(astring),        // 52-bit hash by default
    ahash64 = fnv.hash(astring, 64);    // 64-bit hash specified

console.log(ahash52.hex() == 'a65e7023cd59e');    //true
console.log(ahash52.str() == 'stglysbf6m');       //true
console.log(ahash52.dec() == '2926792616498590'); //true

console.log(ahash64.hex() == '779a65e7023cd2e7');     //true
console.log(ahash64.str() == '1th7cxzlyc0dj');        //true
console.log(ahash64.dec() == '8618312879776256743');  //true

// fast variants
console.log(fnv.fast1a32hex(astring) == 'd58b3fa7');      //true
console.log(fnv.fast1a52hex(astring) == 'a65e7023cd59e'); //true

fnv.seed('foobar testseed');
console.log(fnv.hash(astring, 64).hex() == ahash64.hex()); // false
// ^^ because the default seed is not 'foobar testseed'

API

fnv.hash(string, bitlength)

  • Hash a string using the given bit length (52 is default)
  • returns a FnvHash object

fnv.seed(string)

  • Seed the algorithm to produce different values. Hashing the same value with different seeds will very likely result in different results. To the extent your seed can be random, it can serve as a source of randomness, but nonetheless is not a replacement for a crypgographic PRG (pseudo-random generator).
  • default seed is chongo <Landon Curt Noll> /\>./\\

fnv.useUTF8(bool)

  • Controls UTF-8 awareness of hash functions
  • default is false

FnvHash.str()

Returns the hashed value as an ascii string

FnvHash.hex()

Returns the hashed value as a hexadecimal string

FnvHash.dec()

Returns the hashed value as a decimal string

Fast variants

This functions runs faster because they have no lib-overhead (see benchmarks for more info). They always compute 1a version of hashes and always use default seed. Directly returns hash values (not FnvHash object).

fnv.fast1a32(string)

  • Calculate FNV-1a 32bit hash
  • returns int

fnv.fast1a32hex(string)

  • Calculate FNV-1a 32bit hash
  • returns hex string

fnv.fast1a52(string)

  • Calculate FNV-1a 52bit hash
  • returns int

fnv.fast1a52hex(string)

  • Calculate FNV-1a 52bit hash
  • returns hex string

fnv.fast1a64(string)

  • Calculate FNV-1a 64bit hash
  • returns hex string

fnv.fast1a32utf(string)

  • Calculate FNV-1a 32bit hash
  • handles UTF-8 strings
  • returns int

fnv.fast1a32hexutf(string)

  • Calculate FNV-1a 32bit hash
  • handles UTF-8 strings
  • returns hex string

fnv.fast1a52utf(string)

  • Calculate FNV-1a 52bit hash
  • handles UTF-8 strings
  • returns int

fnv.fast1a52hexutf(string)

  • Calculate FNV-1a 52bit hash
  • handles UTF-8 strings
  • returns hex string

fnv.fast1a64utf(string)

  • Calculate FNV-1a 64bit hash
  • handles UTF-8 strings
  • returns hex string

License

MIT