Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add ellipsis to any text. Choose amount of words to show.
function ellipsis(numOfWords, text, wordCount ) {
wordCount = text.trim().replace(/\s+/g, ' ').split(' ').length;
if(numOfWords <= 0 || numOfWords === wordCount){
return text;
} else {
text = text.trim().split(' ');
text.splice(numOfWords, wordCount, '...');
return text.join(' ');
}
}
//129 bytes, bitches.
function e(n,t,w){w=t.trim().replace(/\s+/g," ").split(' ').length;t=t.trim().split(' ');t.splice(n,w,"...");return t.join(' ');}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.