Skip to content

Instantly share code, notes, and snippets.

@paulakreuger
Last active August 29, 2015 14:00
Show Gist options
  • Save paulakreuger/11205561 to your computer and use it in GitHub Desktop.
Save paulakreuger/11205561 to your computer and use it in GitHub Desktop.
Shorten long strings
/*
==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