truncateWords
Truncates a string to a specified number of words.
truncateWords
Signature
typescript
function truncateWords(str: string, count: number, suffix?: string): stringParameters
str- The string to truncatecount- Maximum number of wordssuffix- String to append (default: "...")
Returns
Truncated string with suffix.
Examples
typescript
import { truncateWords } from 'strio'
truncateWords('The quick brown fox', 2)
// "The quick..."
truncateWords('Hello world', 5)
// "Hello world" (no truncation needed)