@ebay/ebayui-core
Version:
Collection of core eBay components; considered to be the building blocks for all composite structures, pages & apps.
29 lines (28 loc) • 745 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getColorForText = getColorForText;
const backgroundColors = [
"teal",
"light-teal",
"green",
"lime",
"yellow",
"orange",
"magenta",
"pink",
];
function getColorForText(username, color) {
if (color)
return color;
let hash = 0, chr, i;
if (username && username.length > 0) {
for (i = 0; i < username.length; i++) {
chr = username.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0; // Convert to 32bit integer
}
}
const colorCount = backgroundColors.length;
const index = Math.abs(hash) % colorCount;
return backgroundColors[index];
}