Truncate a string to the longest sentence-terminated prefix whose length is โค hardMax, preferring a break โฅ softMin. Never cuts mid-word. Used for <meta description> so Google never renders a truncated last token with a trailing ellipsis.
Supports sentence terminators across multiple scripts:
Latin: ., !, ?, โฆ
CJK (Chinese/Japanese): ใ
Devanagari (Hindi and related Indic scripts): เฅค
Implements seo-metadata-contract.md ยง3.1 + ยง4: every language ships within its own SERP-width window via descriptionWindowForLanguage.
If the input contains no usable sentence boundary and no word boundary within the window (e.g. a single run of non-space chars), the result is guaranteed to be non-empty: it is at least hardMax chars plus a trailing โฆ, so the caller never receives a bare โฆ.
Parameters
text: string
Input prose (markdown emphasis already stripped).
softMin: number = 140
Soft minimum โ prefer truncating at or after this length (default 140).
hardMax: number = 200
Hard maximum โ never return more than this many chars (default 200).
Truncate a string to the longest sentence-terminated prefix whose length is โค
hardMax, preferring a break โฅsoftMin. Never cuts mid-word. Used for<meta description>so Google never renders a truncated last token with a trailing ellipsis.Supports sentence terminators across multiple scripts:
.,!,?,โฆใเฅคImplements
seo-metadata-contract.mdยง3.1 + ยง4: every language ships within its own SERP-width window via descriptionWindowForLanguage.If the input contains no usable sentence boundary and no word boundary within the window (e.g. a single run of non-space chars), the result is guaranteed to be non-empty: it is at least
hardMaxchars plus a trailingโฆ, so the caller never receives a bareโฆ.