Created
January 18, 2019 20:15
-
-
Save clayadavis/746a8ea450f344325b34db2c4a91ca47 to your computer and use it in GitHub Desktop.
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 stringTruncator (numChars, buffer) { | |
buffer = buffer || 3 | |
return function (str) { | |
return function (str) { | |
let cutoff = str.slice(0, numChars).lastIndexOf(' ') | |
if (cutoff === -1) cutoff = numChars | |
str = str.slice(0, cutoff) + '…' | |
} | |
return str | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment