Skip to content

Instantly share code, notes, and snippets.

@lachlan-eagling
Created March 17, 2017 00:43
Show Gist options
  • Select an option

  • Save lachlan-eagling/bd46c31c4bc6fdc3518a24c0a3238cfe to your computer and use it in GitHub Desktop.

Select an option

Save lachlan-eagling/bd46c31c4bc6fdc3518a24c0a3238cfe to your computer and use it in GitHub Desktop.
function truncateString(str, num) {
if(num > 3){
if(str.length > num){
str = str.slice(0, num - 3);
str += "...";
}
} else{
str = str.slice(0, num);
str += "...";
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment