thelounge/client/js/libs/handlebars/colorClass.js

13 lines
252 B
JavaScript
Raw Normal View History

"use strict";
2016-12-18 16:53:28 +01:00
// Generates a string from "color-1" to "color-32" based on an input string
module.exports = function(str) {
2018-01-11 12:33:36 +01:00
let hash = 0;
2018-01-11 12:33:36 +01:00
for (let i = 0; i < str.length; i++) {
2016-12-18 16:53:28 +01:00
hash += str.charCodeAt(i);
}
2016-12-18 16:53:28 +01:00
return "color-" + (1 + hash % 32);
};