added new util fun that genearte new unique color for each item.

This commit is contained in:
Pramod Mahajan 2025-04-18 19:44:05 +05:30
parent c5bfacda3b
commit e5b8ec03df

View File

@ -18,4 +18,34 @@ export const ProjectStatus =(statusId)=>{
default:
break;
}
}
}
// for different color for each user
export function hashString(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = (hash << 5) - hash + char;
}
return hash;
}
// Map a hash value to a Bootstrap background class
export function getBgClassFromHash(str) {
const bgClasses = [
"primary",
"secondary",
"success",
"danger",
"warning",
"info",
"dark",
"light",
];
const hash = hashString(str);
const index = Math.abs(hash % bgClasses.length);
return bgClasses[index];
}