2017-03-18 09:21:18 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-12-18 15:53:28 +00:00
|
|
|
// Generates a string from "color-1" to "color-32" based on an input string
|
2019-11-16 17:24:03 +00:00
|
|
|
export default (str) => {
|
2018-01-11 11:33:36 +00:00
|
|
|
let hash = 0;
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
for (let i = 0; i < str.length; i++) {
|
2016-12-18 15:53:28 +00:00
|
|
|
hash += str.charCodeAt(i);
|
2016-05-12 06:15:02 +00:00
|
|
|
}
|
2016-12-18 15:53:28 +00:00
|
|
|
|
2018-07-03 09:51:10 +00:00
|
|
|
/*
|
|
|
|
Modulo 32 lets us be case insensitive for ascii
|
|
|
|
due to A being ascii 65 (100 0001)
|
|
|
|
while a being ascii 97 (110 0001)
|
|
|
|
*/
|
2019-07-17 09:33:59 +00:00
|
|
|
return "color-" + (1 + (hash % 32));
|
2016-12-18 15:53:28 +00:00
|
|
|
};
|