Repository URL to install this package:
|
Version:
1.1.0 ▾
|
string-hash
/
index.js
|
|---|
module.exports = function(str) {
var hash = 5381,
i = str.length
while(i)
hash = (hash * 33) ^ str.charCodeAt(--i)
/* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
* integers. Since we want the results to be always positive, if the high bit
* is set, unset it and add it back in through (64-bit IEEE) addition. */
return hash >= 0 ? hash : (hash & 0x7FFFFFFF) + 0x80000000
}