Skip to content

truncate

truncate(params): string

Defined in: strings/truncate/index.ts:23

Truncates a string to a specified length with an optional suffix.

TruncateParams

The parameters object

string

The truncated string, or the original if shorter than length

truncate({ str: "Hello, World!", length: 5 });
// => "Hello..."

shorten text, ellipsis, cut string, text overflow

Error if str is not a string

Error if length is not a positive integer