forked from ddrilling/asb_cloud_front
Добавлен метод обрезки для длинных строк
This commit is contained in:
parent
99292bd80d
commit
daad22ce9a
8
src/utils/string.ts
Normal file
8
src/utils/string.ts
Normal 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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user