From 9fdf46889ca68dddfe8eb4ca386b602164e41c65 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Tue, 11 Nov 2025 21:32:57 +0000 Subject: [PATCH] feat(Text): add truncate method for string length limitation --- Common/Types/Text.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Common/Types/Text.ts b/Common/Types/Text.ts index 18d51a280b..4791001896 100644 --- a/Common/Types/Text.ts +++ b/Common/Types/Text.ts @@ -297,4 +297,19 @@ export default class Text { ): string { return sentence.split(search).join(replaceBy); } + + public static truncate( + value: string | null | undefined, + maxLength: number, + ): string | undefined { + if (value === null || value === undefined) { + return undefined; + } + + if (maxLength <= 0) { + return ""; + } + + return value.length > maxLength ? value.slice(0, maxLength) : value; + } }