discourse/app/assets/javascripts/discourse/lib/hash.js.es6
2018-06-15 17:03:24 +02:00

12 lines
290 B
JavaScript

/*eslint no-bitwise:0 */
// Note: before changing this be aware the same algo is used server side for avatars.
export function hashString(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i);
hash |= 0;
}
return hash;
}