Last active
April 4, 2016 03:13
-
-
Save ebragaparah/64e6bbbdaf46a42341921a6b40caa7ee to your computer and use it in GitHub Desktop.
It's an approach that truncate a string given the maximum size, but following some conditions
This file contains 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
function truncateString(str, num) { | |
var points = '...'; | |
return num < str.length ? | |
((num < points.length) ? | |
str.substr(0, num).concat(points) : | |
str.substr(0, num - points.length).concat(points)) : | |
str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment