@nextcloud/vue
Version:
Nextcloud vue components
27 lines (26 loc) • 751 B
JavaScript
import { G as GenColors } from "./GenColors-DfwXw1-o.mjs";
import md5 from "md5";
const usernameToColor = function(username) {
let hash = username.toLowerCase();
if (hash.match(/^([0-9a-f]{4}-?){8}$/) === null) {
hash = md5(hash);
}
hash = hash.replace(/[^0-9a-f]/g, "");
const steps = 6;
const finalPalette = GenColors(steps);
function hashToInt(hash2, maximum) {
let finalInt = 0;
const result = [];
for (let i = 0; i < hash2.length; i++) {
result.push(parseInt(hash2.charAt(i), 16) % 16);
}
for (const j in result) {
finalInt += result[j];
}
return parseInt(parseInt(finalInt, 10) % maximum, 10);
}
return finalPalette[hashToInt(hash, steps * 3)];
};
export {
usernameToColor as u
};