Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Last active May 30, 2023 12:08
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 AitorAlejandro/9d3da1c79c935940a0eb272f65ecb25a to your computer and use it in GitHub Desktop.
Save AitorAlejandro/9d3da1c79c935940a0eb272f65ecb25a to your computer and use it in GitHub Desktop.
Truncate strings
function truncate(str, length) {
return str.length > length
? `${str.substr(0, length)}...`
: str;
}
function truncate(str: string, length: number): string {
return str.length > length
? `${str.substr(0, length)}...`
: str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment