vn-verdnaturachat/app/utils/avatarInitialsAndColor.js

17 lines
395 B
JavaScript
Raw Normal View History

2017-08-13 03:19:14 +00:00
import { AVATAR_COLORS } from '../constants/colors';
export default function(username = '') {
if (username === '') {
return {
initials: '',
colors: 'transparent'
};
}
2017-08-13 03:19:14 +00:00
const position = username.length % AVATAR_COLORS.length;
const color = AVATAR_COLORS[position];
const initials = username.replace(/[^A-Za-z0-9]/g, '').substr(0, 1).toUpperCase();
2017-08-13 03:19:14 +00:00
return { initials, color };
}