Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / avatars / hash-avatar-to-cdn.js
blobd1acd999c3426dd0a58190918294a68d435eac35
1 'use strict';
3 module.exports = function hash(str) {
4 if (!str || !str.length) return 1;
6 /* djb2: http://www.cse.yorku.ca/~oz/hash.html */
7 var f = 5381;
8 for (var i = 0; i < str.length && i < 8; i++) {
9 // Limit to the first 8 chars
10 f = (f << 5) + f + str.charCodeAt(i); /* hash * 33 + c */
13 return (f > 0 ? f : -f) % 3; // defaults to 4 buckets;