( text: string, maxLength: number, )
| 164 | * Appends an ellipsis when truncation occurs. |
| 165 | */ |
| 166 | export const truncateAtWordBoundary = ( |
| 167 | text: string, |
| 168 | maxLength: number, |
| 169 | ): string => { |
| 170 | if (!text || text.length <= maxLength) { |
| 171 | return text || ''; |
| 172 | } |
| 173 | |
| 174 | const truncated = text.slice(0, maxLength); |
| 175 | const lastSpace = truncated.lastIndexOf(' '); |
| 176 | |
| 177 | return `${lastSpace > 0 ? truncated.slice(0, lastSpace) : truncated}...`; |
| 178 | }; |
| 179 | |
| 180 | /** |
| 181 | * Regex to test if a string contains special characters. |
no outgoing calls
no test coverage detected