What is hash-sum?
The hash-sum npm package is used to create hash digests of JavaScript objects, arrays, strings, and other serializable values. It is a fast and dependency-free hashing function that generates a hex-encoded hash.
What are hash-sum's main functionalities?
Hashing strings
This feature allows you to create a hash from a string. The hash is deterministic, meaning the same string will always result in the same hash.
"hashSum('Hello, World!')"
Hashing objects
You can hash JavaScript objects, which is useful for checking if objects have changed or for using objects as keys in caching mechanisms.
"hashSum({ key: 'value' })"
Hashing arrays
Arrays can also be hashed, which is helpful for creating unique identifiers for sets of items or for caching purposes.
"hashSum(['one', 'two', 'three'])"
Hashing other serializable values
The package can hash other serializable values such as numbers, ensuring a wide range of data types can be hashed.
"hashSum(12345)"
Other packages similar to hash-sum
md5
The md5 package is a JavaScript function for hashing messages with MD5. Unlike hash-sum, which is designed for hashing serializable JavaScript values, md5 is specifically focused on creating MD5 hashes of strings.
crypto-js
Crypto-js is a collection of cryptography algorithms implemented in JavaScript. It offers a variety of hash functions like SHA-1, SHA-256, and MD5. It is more feature-rich compared to hash-sum but also larger and with more dependencies.
object-hash
Object-hash provides a complete hashing solution for JavaScript objects, supporting different algorithms like SHA-1 and MD5. It is similar to hash-sum but offers more options for customization and different hash algorithms.
hash-sum
blazing fast unique hash generator
install
npm i hash-sum -S
sum(value)
yields a four-byte hexadecimal hash based off of value
.
# creates unique hashes
creates unique hashes
4d237d49 from: [ 0, 1, 2, 3 ]
766ec173 from: { url: 12 }
2f473108 from: { headers: 12 }
23308836 from: { headers: 122 }
062bce44 from: { headers: '122' }
acb9f66e from: { headers: { accept: 'text/plain' } }
1c365a2d from: { payload: [ 0, 1, 2, 3 ], headers: [ { a: 'b' } ] }
7319ae9d from: { a: [Function] }
8a3a0e86 from: { b: [Function] }
b6d7f5d4 from: { b: [Function] }
6c95fc65 from: function () {}
2941766e from: function (a) {}
294f8def from: function (b) {}
2d9c0cb8 from: function (a) { return a;}
ed5c63fc from: function (a) {return a;}
bba68bf6 from: ''
2d27667d from: 'null'
774b96ed from: 'false'
2d2a1684 from: 'true'
8daa1a0c from: '0'
8daa1a0a from: '1'
e38f07cc from: 'void 0'
6037ea1a from: 'undefined'
9b7df12e from: null
3c206f76 from: false
01e34ba8 from: true
1a96284a from: 0
1a96284b from: 1
29172c1a from: undefined
4505230f from: {}
3718c6e8 from: { a: {}, b: {} }
caec4ca8 from: { b: {}, a: {} }
5d844489 from: []
ok 1 should be equal
license
MIT