dependabit / utils/src / truncate
Function: truncate()
ts
function truncate(
str,
maxLength,
suffix?): string;Defined in: packages/utils/src/string.ts:65
Truncates a string to a maximum length, appending a suffix if truncated.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
str | string | undefined | The string to truncate. |
maxLength | number | undefined | Maximum total output length, including the suffix. |
suffix | string | '...' | Suffix to append when truncation occurs. |
Returns
string
The truncated string.
Default Value
suffix = '...'
Example
ts
truncate('Hello World', 8); // 'Hello...'