chore: add user initial helper

This commit is contained in:
Muhsin Keloth
2024-04-25 23:46:54 +05:30
parent 6b81865f56
commit d75da3931e
4 changed files with 20 additions and 12 deletions
@@ -1,3 +1,9 @@
export const replaceRouteWithReload = url => {
window.location = url;
};
export const userInitial = name => {
const parts = name.split(/[ -]/).filter(Boolean);
let initials = parts.map(part => part[0].toUpperCase()).join('');
return initials.slice(0, 2);
};
@@ -0,0 +1,10 @@
import { userInitial } from '../CommonHelper';
describe('#userInitial', () => {
it('returns the initials of the user', () => {
expect(userInitial('John Doe')).toEqual('JD');
expect(userInitial('John')).toEqual('J');
expect(userInitial('John-Doe')).toEqual('JD');
expect(userInitial('John Doe Smith')).toEqual('JD');
});
});