Is there any JavaScript Library to intelligently truncate strings?

Posted by j0ker on Stack Overflow See other posts from Stack Overflow or by j0ker
Published on 2012-11-15T10:58:06Z Indexed on 2012/11/15 10:59 UTC
Read the original article Hit count: 405

I need to truncate strings in a side menu to make the fit into a div without a linebreak. The divs have a fixed width. I'm looking for a library to do that for me.

If a string is too long to fit into the div, it should be truncated like:

<div>This string is too long</div> ==> <div>This string is...ong</div>

As you can see, the string is not only truncated by an ellipsis but the last three letters are also visible. This is meant to increase readability. The truncation should not care about spaces.

Does anyone know of a library that includes such functionality? We're mainly using jQuery throughout the project.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-library