limitString()function
limitString(str: string, maxLength: number, append = "…"): void
| Param | Type | |
|---|---|---|
str | string | The string to limit. required |
maxLength | number | The maximum length of the returned string (before append is added). required |
append | unknown | The string to append when a limit is applied (defaults to "…"). Defaults to "…" |
| Return | |
|---|---|
unknown | str unchanged if it's shorter than maxLength, otherwise truncated with append added. |
Limit a string to a given length.
- Stops at the last space inside
maxLength - Appends an
…ellipses after the string (but only if a limit is applied).
Examples
limitString("the quick brown fox", 9) // "the quick…"