Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ibm
GitHub Repository: ibm/watson-machine-learning-samples
Path: blob/master/cloud/ai-service-apps/nextjs-carbon-react-ui/src/utils/user-util.js
6408 views
1
import { USER_COLOR_POOL } from "./constants";
2
3
export function getUserInitials({ givenName, familyName }) {
4
if (!givenName) {
5
return "";
6
}
7
8
const initialsA = givenName[0] + familyName[0];
9
const initialsB = givenName[0] + givenName[1];
10
11
return familyName ? initialsA : initialsB;
12
}
13
14
export function mapUserColor(userName) {
15
if (!userName) {
16
return USER_COLOR_POOL[0];
17
}
18
19
let colorPoolIndex = 0;
20
[...userName].forEach((character) => {
21
colorPoolIndex += character.charCodeAt(0);
22
});
23
colorPoolIndex %= USER_COLOR_POOL.length;
24
25
return USER_COLOR_POOL[colorPoolIndex];
26
}
27
28