- truncate(maxLength: number, suffix?: string, separator?: string): ((str: string, length?: number) => string)
-
Parameters
-
maxLength: number
-
suffix: string = ""
-
separator: string = ""
Returns ((str: string, length?: number) => string)
-
- (str: string, length?: number): string
-
Parameters
-
str: string
-
length: number = str.length
Returns string
Truncates a string to a maximum length.
suffixlength does not influencemaxLength.If
separatoris provided, it will look for the closestseparatorto truncate toExample
Truncate to 3 characters
Example
Truncate to 3 characters, and add
"..."suffixExample
Truncate to the closest space (
" ") up to 9 charactersReturns
the truncated String