@@ -8,8 +8,50 @@ const TRAILING_PUNCT = /[,;:\-–—]+$/;
88 * @param suffix - Suffix to append when text is truncated (default: '...')
99 * @returns The excerpted text
1010 * @example
11- * excerpt('The quick brown fox jumps over the lazy dog', 20) // 'The quick brown fox...'
12- * excerpt('Hello world. This is a test.', 15) // 'Hello world...'
11+ * ```ts
12+ * // Basic usage with word boundary preservation
13+ * excerpt('The quick brown fox jumps over the lazy dog', 20)
14+ * // 'The quick brown fox...' (cuts at word boundary)
15+ *
16+ * // Smart punctuation handling
17+ * excerpt('Hello world. This is a test.', 15)
18+ * // 'Hello world..' (preserves sentence end)
19+ *
20+ * // Function overloads with custom suffix
21+ * excerpt('Long article content here', 50) // Default '...' suffix
22+ * excerpt('Long article content here', 50, '…') // Unicode ellipsis
23+ * excerpt('Long article content here', 50, ' [more]') // Custom text
24+ *
25+ * // Type-safe blog post previews
26+ * interface BlogPost {
27+ * title: string
28+ * content: string
29+ * published: Date
30+ * }
31+ * function getPostPreview(post: BlogPost): string {
32+ * return excerpt(post.content, 150, '...')
33+ * }
34+ *
35+ * // Search result snippets
36+ * interface SearchHit {
37+ * document: string
38+ * score: number
39+ * }
40+ * const results: SearchHit[] = search(query)
41+ * const snippets = results.map(hit => ({
42+ * ...hit,
43+ * snippet: excerpt(hit.document, 200)
44+ * }))
45+ *
46+ * // Null-safe excerpting
47+ * const description: string | null = getDescription()
48+ * const preview = description ? excerpt(description, 100) : 'No description available'
49+ *
50+ * // Smart handling of edge cases
51+ * excerpt('SingleLongWordWithoutSpaces', 10) // 'SingleLong...'
52+ * excerpt('Word', 10) // 'Word' (no truncation needed)
53+ * excerpt('Sentence ending here.', 21) // 'Sentence ending here..' (smart punctuation)
54+ * ```
1355 */
1456export function excerpt ( text : string , length : number ) : string ;
1557export function excerpt ( text : string , length : number , suffix : string ) : string ;
0 commit comments