From eca3b49f1bf246c2f4f83a0f3991b89edf366773 Mon Sep 17 00:00:00 2001 From: Adithya Sreyaj Date: Tue, 19 Sep 2023 16:20:08 +0530 Subject: [PATCH] feat: handle empty string in displaystring pipe --- .../src/utilities/formatters/string/string-formatter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/projects/common/src/utilities/formatters/string/string-formatter.ts b/projects/common/src/utilities/formatters/string/string-formatter.ts index 56a6babb0..d81f6360a 100644 --- a/projects/common/src/utilities/formatters/string/string-formatter.ts +++ b/projects/common/src/utilities/formatters/string/string-formatter.ts @@ -1,3 +1,5 @@ +import { isEmpty } from 'lodash-es'; + export const displayString = (provided?: unknown, defaultValueOnEmpty: string = '-'): string => { if (provided === null || provided === 'null') { return defaultValueOnEmpty; @@ -13,7 +15,7 @@ export const displayString = (provided?: unknown, defaultValueOnEmpty: string = case 'function': return 'Function'; case 'string': - return provided; + return !isEmpty(provided.trim()) ? provided : defaultValueOnEmpty; case 'boolean': case 'number': case 'bigint':