@visulima/string
Version:
Functions for manipulating strings.
26 lines (25 loc) • 1.04 kB
TypeScript
import { TruncateOptions } from "./truncate.js";
import "./get-string-truncated-width.js";
/**
* Truncates a sentence to be under the given character limit and strips HTML tags from it.
* This function first removes all HTML tags and decodes HTML entities, then truncates
* the resulting plain text to the specified character limit using the truncate function.
* @example
* ```typescript
* excerpt('<p>Hello <strong>world</strong>!</p>', 10);
* // => 'Hello worl…'
*
* excerpt('<div>This is a <em>long</em> text</div>', 20, { ellipsis: '...' });
* // => 'This is a long text'
* ```
* @param html The HTML string to truncate
* @param limit Maximum character limit for the truncated string
* @param options Configuration options for truncation
* @returns The truncated plain text string with HTML tags removed
*/
declare const excerpt: (html: string, limit: number, options?: ExcerptOptions) => string;
/**
* Options for the excerpt function
*/
type ExcerptOptions = Omit<TruncateOptions, "position">;
export { ExcerptOptions, excerpt };