Skip to content

Instantly share code, notes, and snippets.

@pedroCX486
Last active December 28, 2019 21:16
Show Gist options
  • Save pedroCX486/21e6996d7aee715e369d6148c83b38b5 to your computer and use it in GitHub Desktop.
Save pedroCX486/21e6996d7aee715e369d6148c83b38b5 to your computer and use it in GitHub Desktop.
Truncate in JS/TS
truncate(text, length) {
if (text.length <= length) {
return text;
} else {
return text.substring(0, length) + '...';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment