Skip to content

Instantly share code, notes, and snippets.

@fastcodecoq
Created April 27, 2015 00:23
Show Gist options
  • Save fastcodecoq/9be651dbf4a0781b173a to your computer and use it in GitHub Desktop.
Save fastcodecoq/9be651dbf4a0781b173a to your computer and use it in GitHub Desktop.
String.prototype.ellipsis = function(limit){
var limit = limit || 50;
console.log(this +'');
var st = (this + '').substring(0,limit);
var complete = '';
if(this[limit] != ' ')
for(i=limit;i<this.length;i++)
if(this[i] != ' ')
complete += this[i];
else
break;
st = st + complete + '...';
return st;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment