leadingSentence
Extracts the leading sentence from a string.
null and undefined are passed through unchanged.
A sentence boundary is detected at the first occurrence of ., ?, !,
…, or ; followed by whitespace or end of string. Newlines are collapsed
to spaces before matching.
If no boundary is found the entire (cleaned) string is returned.
To cap the result at a maximum length, combine with truncate:
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | string | The source string |
Returns
Section titled “Returns”string — The first sentence, including its terminal character; or null/undefined if input is nullish
Examples
Section titled “Examples”Extract the leading sentence
Section titled “Extract the leading sentence”Returns the first sentence, terminated by . ? or !.
Works with ? and !
Section titled “Works with ? and !”Recognises question marks and exclamation marks as sentence terminators.
Cap length by combining with truncate
Section titled “Cap length by combining with truncate”Use truncate to limit the result to a fixed number of characters.
