Skip to content

Instantly share code, notes, and snippets.

@clayadavis
Last active August 23, 2016 15:08
Show Gist options
  • Save clayadavis/8747396 to your computer and use it in GitHub Desktop.
Save clayadavis/8747396 to your computer and use it in GitHub Desktop.
Truncate Javascript string to fixed number of characters, then add ellipsis.
function truncator(len){
return function(txt){
if (txt.length > len){
txt = txt.substring(0, len).replace(/\W*\w*$/, '') + '\u2026';
}
return txt
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment