Created
July 20, 2011 18:25
-
-
Save qwertypants/1095559 to your computer and use it in GitHub Desktop.
Add ellipsis to any text. Choose amount of words to show.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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