From b8790200e98c21719730c706380d2f66551bb568 Mon Sep 17 00:00:00 2001 From: Danny Liu Date: Thu, 4 Apr 2024 20:05:39 -0700 Subject: [PATCH] refac: code style --- src/lib/utils/index.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 636f68eee..0f7a5ae13 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -97,24 +97,25 @@ export const getGravatarURL = (email) => { }; export const generateInitialsImage = (name) => { - const canvas = document.createElement('canvas'); - const ctx = canvas.getContext('2d'); - canvas.width = 100; - canvas.height = 100; + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + canvas.width = 100; + canvas.height = 100; - ctx.fillStyle = '#F39C12'; - ctx.fillRect(0, 0, canvas.width, canvas.height); + ctx.fillStyle = '#F39C12'; + ctx.fillRect(0, 0, canvas.width, canvas.height); - ctx.fillStyle = '#FFFFFF'; - ctx.font = '40px Helvetica'; - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; + ctx.fillStyle = '#FFFFFF'; + ctx.font = '40px Helvetica'; + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; - const initials = name.trim().length > 0 ? name[0] + (name.trim().split(' ').length > 1 ? name[name.lastIndexOf(' ') + 1] : '') : ''; + const sanitizedName = name.trim(); + const initials = sanitizedName.length > 0 ? sanitizedName[0] + (sanitizedName.split(' ').length > 1 ? sanitizedName[sanitizedName.lastIndexOf(' ') + 1] : '') : ''; - ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2); + ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2); - return canvas.toDataURL(); + return canvas.toDataURL(); }; export const copyToClipboard = (text) => {