Created
May 23, 2016 05:19
-
-
Save englishextra/b4939b3430da4b55d731201460d3decb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* truncate a text or line with ellipsis | |
* stackoverflow.com/questions/4700226/i-want-to-truncate-a-text-or-line-with-ellipsis-using-javascript | |
* gist.github.com/englishextra/b4939b3430da4b55d731201460d3decb | |
*/ | |
function truncString(str, max, add) { | |
add = add || "\u2026"; | |
return (typeof str === "string" && str.length > max ? str.substring(0, max) + add : str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment