index.js 408 B

1234567891011121314151617
  1. "use strict";
  2. function hash(str) {
  3. var hash = 5381,
  4. i = str.length;
  5. while(i) {
  6. hash = (hash * 33) ^ str.charCodeAt(--i);
  7. }
  8. /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
  9. * integers. Since we want the results to be always positive, convert the
  10. * signed int to an unsigned by doing an unsigned bitshift. */
  11. return hash >>> 0;
  12. }
  13. module.exports = hash;