Truncates a given text to a specified length and appends ellipsis (...) at the end if needed.
Usage:
import{trunc}from'helper-toolkit-ts'constsentence='Lorem ipsum dolor sit amet, consectetur adipiscing elit.';consttruncatedSentence=trunc(sentence,20,true);console.log(truncatedSentence);// Output: 'Lorem ipsum dolor...'
Arguments:
Name
Type
Description
text
string
input text
n
number
max number of characters to keep
useWordBoundary
boolean
if true, keep the whole word at end
Returns:
Type
Description
string
return the string end with ellipsis(...) if length of input string is longer than the max n
Miscellaneous Helper Functions
generateUID
Generates a unique identifier (UUID) using the version 4 format.