Skip to content

Instantly share code, notes, and snippets.

@fouad
Created January 19, 2019 22:26
Show Gist options
  • Save fouad/0593048b654ed9af9afdb4e65427395f to your computer and use it in GitHub Desktop.
Save fouad/0593048b654ed9af9afdb4e65427395f to your computer and use it in GitHub Desktop.
// Shorten strings over 40 characters
//
// input = FirstTwelveCharactersAndTheLastFifteen
// output = FirstTwelvec...dTheLastFifteen
function shorten(str) {
return str.replace(
/[^"]{40,}/g,
match => `${match.substring(0, 12)}...${match.substring(match.length - 15)}`
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment