Skip to content

Instantly share code, notes, and snippets.

@enggsuraj
Created December 17, 2020 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enggsuraj/e89660fdc3e14ea71b34b7509a49622c to your computer and use it in GitHub Desktop.
Save enggsuraj/e89660fdc3e14ea71b34b7509a49622c to your computer and use it in GitHub Desktop.
export function truncate(str) {
const length = 100;
const ending = "...";
if (str.length > length) {
return str.substring(0, length - ending.length) + ending;
} else {
return str;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment