Skip to content

Instantly share code, notes, and snippets.

@qwertypants
Created July 20, 2011 18:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save qwertypants/1095559 to your computer and use it in GitHub Desktop.
Save qwertypants/1095559 to your computer and use it in GitHub Desktop.
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