From daad22ce9acaa0fb20b2ed3455bc9c696645bcb1 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Fri, 17 Dec 2021 10:03:25 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BE=D0=B1=D1=80?= =?UTF-8?q?=D0=B5=D0=B7=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D0=B8=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/string.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/utils/string.ts diff --git a/src/utils/string.ts b/src/utils/string.ts new file mode 100644 index 0000000..debbcf3 --- /dev/null +++ b/src/utils/string.ts @@ -0,0 +1,8 @@ +export const makeStringCutter = (maxLength = 100, separator = ' ', suffix = '...') => (comment?: string) => { + if (!comment || comment.length < maxLength) + return comment + let lastSep = comment.lastIndexOf(separator, maxLength) + if (lastSep < 0) + return comment.substring(0, maxLength - suffix.length) + suffix + return comment.substring(0, lastSep) +}