Skip to content

Instantly share code, notes, and snippets.

@gwenhael-le-moine
Last active December 25, 2015 14:39
Show Gist options
  • Save gwenhael-le-moine/6992227 to your computer and use it in GitHub Desktop.
Save gwenhael-le-moine/6992227 to your computer and use it in GitHub Desktop.
var clever_truncate = function( text, length ) {
if ( text.length > length ) {
var result = text.substring( 0, length );
result = result.substring( 0, result.lastIndexOf(' ') );
result += '…';
return result;
} else {
return text;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment