Добавлен метод обрезки для длинных строк

This commit is contained in:
Александр Сироткин 2021-12-17 10:03:25 +05:00
parent 99292bd80d
commit daad22ce9a

8
src/utils/string.ts Normal file
View File

@ -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)
}