From c52cc46d2c8d4d6ca57f52ab1402a7943edb5d9b Mon Sep 17 00:00:00 2001 From: Danny Liu Date: Thu, 4 Apr 2024 13:23:59 -0700 Subject: [PATCH] feat: initial avatar set to first letter of firstname, first letter of lastname --- src/lib/utils/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 32830fed7..be08cae94 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -109,10 +109,10 @@ export const generateInitialsImage = (name) => { ctx.font = '40px Helvetica'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; - const initials = name - .split(' ') - .map((word) => word[0]) - .join(''); + const firstNameInitial = name[0]; + const lastNameInitial = name.lastIndexOf(' ') > -1 ? name[name.lastIndexOf(' ') + 1] : ''; + const initials = `${firstNameInitial}${lastNameInitial}`.toUpperCase() + ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2); return canvas.toDataURL();