From 3f5bbf336cb7e5b50dcfcc2f2771e49241d481a4 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:16:38 +0530 Subject: [PATCH] fix: truncate text function (#431) --- apps/app/helpers/string.helper.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/app/helpers/string.helper.ts b/apps/app/helpers/string.helper.ts index f1c64bdf5..d3ae3ae26 100644 --- a/apps/app/helpers/string.helper.ts +++ b/apps/app/helpers/string.helper.ts @@ -4,8 +4,11 @@ export const replaceUnderscoreIfSnakeCase = (str: string) => str.replace(/_/g, " export const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1); -export const truncateText = (str: string, length: number) => - str.length > length ? `${str.substring(0, length)}...` : str; +export const truncateText = (str: string, length: number) => { + if (!str || str === "") return ""; + + return str.length > length ? `${str.substring(0, length)}...` : str; +}; export const createSimilarString = (str: string) => { const shuffled = str