Last active
August 29, 2015 14:00
-
-
Save paulakreuger/11205561 to your computer and use it in GitHub Desktop.
Shorten long strings
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
/* | |
==SHORTEN LONG STRINGS | |
-----------------------------------------------------*/ | |
function truncateLongText(elem, maxwidth, sufix) { | |
if (elem === null) { | |
return ''; | |
} | |
elem = String(elem); | |
var newElem; | |
if (elem.length > maxwidth) { | |
newElem = elem.substring(0, maxwidth) + sufix; | |
} else { | |
newElem = elem; | |
} | |
return newElem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment