Skip to content

truncate

Truncates a long string to a specified length, optionally appending an ellipsis after the string.

Parameters

NameTypeRequiredDefault
strstring
lengthnumber
ellipsisnamedstring''

named parameters are passed as named parameters in Dart and keyword arguments in Python.

Returns

string

Examples

javascript
truncate('hello', 3); // Returns 'hel'
truncate('hello', 2, '...'); // Returns 'he...'
dart
truncate('hello', 3); // Returns 'hel'
truncate('hello', 2, ellipsis: '...'); // Returns 'he...'
python
truncate('hello', 3)  # Returns 'hel'
truncate('hello', 2, '...')  # Returns 'he...'

Released under the MIT License