Skip to content

Instantly share code, notes, and snippets.

@clayadavis
Created January 18, 2019 20:15
Show Gist options
  • Save clayadavis/746a8ea450f344325b34db2c4a91ca47 to your computer and use it in GitHub Desktop.
Save clayadavis/746a8ea450f344325b34db2c4a91ca47 to your computer and use it in GitHub Desktop.
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