Last active
August 23, 2016 15:08
-
-
Save clayadavis/8747396 to your computer and use it in GitHub Desktop.
Truncate Javascript string to fixed number of characters, then add ellipsis.
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 truncator(len){ | |
return function(txt){ | |
if (txt.length > len){ | |
txt = txt.substring(0, len).replace(/\W*\w*$/, '') + '\u2026'; | |
} | |
return txt | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment