Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Forked from qwertypants/ellipsis.js
Created July 20, 2011 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzedword/1095601 to your computer and use it in GitHub Desktop.
Save buzzedword/1095601 to your computer and use it in GitHub Desktop.
Add ellipsis to any text. Choose amount of words to show.
String.prototype.ellipsis = function(numOfWords, _text, wordCount ) {
_text = this;
wordCount = _text.trim().replace(/\s+/g, " ").split(' ').length;
_text = _text.trim().split(' ');
_text.splice(numOfWords, wordCount, "...");
return _text.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment