Skip to content

zackng/truncate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

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..'

About

Truncate Text and append ellipsis (JS)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published