Skip to content

Latest commit

 

History

History
15 lines (10 loc) · 612 Bytes

README.md

File metadata and controls

15 lines (10 loc) · 612 Bytes

Truncate

Truncate Text and append ellipsis (JS)

Truncate your string and append ellipsis to end of string.

How to use?
var text = 'Hello how are you?';
console.log(text.truncate(5)); // output 'Hello..'

If the truncated index is a 'space'; ' ', ellipsis will be appended to the previous index.
console.log(text.truncate(6)); //output 'Hello..' instead of 'Hello ..'

If ellipsis is appended to a partial word that only has 1 or 2 character, it will be appended to previous index so it don't looks ugly
console.log(text.truncate(7); //output 'Hello..' instead of 'Hello h..'