Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

String.ts

8 lines206 Bytes

1export function truncate(text: string, maxLength = 50): string {
2 const trimmed = text.trim();
3 if (trimmed.length <= maxLength) {
4 return trimmed;
5 }
6​
7 return `${trimmed.slice(0, maxLength)}...`;
8}