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