Skip to content

Instantly share code, notes, and snippets.

@freshsnippets
Forked from qwertypants/ellipsis.js
Created March 8, 2012 16:53
Show Gist options
  • Save freshsnippets/2002036 to your computer and use it in GitHub Desktop.
Save freshsnippets/2002036 to your computer and use it in GitHub Desktop.
JavaScript: Add ellipsis
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