
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Javascript FNV-1a Hashing Algorithm up to 1024 bits, with highly optimized 32bit and 52bit implementations.
The fnv-plus npm package is a JavaScript implementation of the FNV (Fowler-Noll-Vo) hash function. It provides fast and efficient hashing capabilities, which are useful for various applications such as data integrity checks, hash tables, and more.
Hashing a String
This feature allows you to hash a string using the FNV hash function. The resulting hash can be used for data integrity checks or as a unique identifier.
const fnv = require('fnv-plus');
const hash = fnv.hash('example string');
console.log(hash.hex());
Hashing a Buffer
This feature allows you to hash a buffer, which is useful for binary data. The resulting hash can be used for various purposes, including data integrity and unique identification.
const fnv = require('fnv-plus');
const buffer = Buffer.from('example buffer');
const hash = fnv.hash(buffer);
console.log(hash.hex());
Hashing with Different Bit Lengths
This feature allows you to hash data with different bit lengths (32-bit or 64-bit). This can be useful depending on the specific requirements of your application.
const fnv = require('fnv-plus');
const hash32 = fnv.hash('example string', 32);
const hash64 = fnv.hash('example string', 64);
console.log(hash32.hex());
console.log(hash64.hex());
hash.js is a library that provides various hash functions including SHA, RIPEMD, and more. It is more versatile compared to fnv-plus as it supports a wider range of hash functions.
The built-in Node.js 'crypto' module provides a wide range of cryptographic functionalities, including various hash functions like SHA-256, SHA-512, and more. It is more comprehensive compared to fnv-plus but may be overkill for simple FNV hashing needs.
murmurhash is a library that implements the MurmurHash algorithm, which is known for its speed and good distribution. It is similar to fnv-plus in terms of providing a fast hashing function but uses a different algorithm.
Javascript FNV-1a Hashing Algorithm up to 1024 bits, with highly optimized 32bit and 52bit implementations.
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.
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.hash()
function can now take arbitrary Javascript objects as input.$ npm install fnv-plus --save
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'
fnv.hash(string, bitlength)
FnvHash
objectfnv.seed(string)
chongo <Landon Curt Noll> /\>./\\
fnv.useUTF8(bool)
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
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)
fnv.fast1a32hex(string)
fnv.fast1a52(string)
fnv.fast1a52hex(string)
fnv.fast1a64(string)
fnv.fast1a32utf(string)
fnv.fast1a32hexutf(string)
fnv.fast1a52utf(string)
fnv.fast1a52hexutf(string)
fnv.fast1a64utf(string)
MIT
FAQs
Javascript FNV-1a Hashing Algorithm up to 1024 bits, with highly optimized 32bit and 52bit implementations.
The npm package fnv-plus receives a total of 144,098 weekly downloads. As such, fnv-plus popularity was classified as popular.
We found that fnv-plus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.