vanillajs-helpers

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS

View the Project on GitHub Tokimon/vanillajs-helpers

vanillajs-helpers > “truncate”

External module: “truncate”

Index

Interfaces

Functions


Functions

truncate

truncate(str: string, settings?: TruncateSettings): string

Defined in truncate.ts:26

Limits a string to a given number of characters and adds ‘…’ in the end

truncate('No max length to the string'); // -> No max limit to the string length
truncate('With a max length to the string', { maxLength: 10 }); // -> With a max...
truncate('With a max length to the string and a differnet ending', { maxLength: 10, end: ' <---' }); // -> With a max <---

Parameters:

Param Type Default value Description
str string - String to truncate
settings TruncateSettings {} Settings to use with the truncation

Returns: string