MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / firstSentence

Function firstSentence

apps/docs/scripts/docs-catalog-lib.mjs:151–169  ·  view source on GitHub ↗
(paragraph)

Source from the content-addressed store, hash-verified

149}
150
151function firstSentence(paragraph) {
152 const collapsed = paragraph.replace(/\s+/gu, " ").trim();
153
154 if (collapsed === "") {
155 return "";
156 }
157
158 const sentence = /^(.*?[.!?])(?:\s|$)/u.exec(collapsed)?.[1];
159
160 if (sentence !== undefined) {
161 return sentence;
162 }
163
164 // No sentence terminator: this is a colon/semicolon lead-in (e.g.
165 // "Scaffolds a new API resource:") whose detail lives in an indented list
166 // we deliberately dropped. Normalize the dangling mark to a period so the
167 // catalog reads as a complete summary instead of a fragment.
168 return collapsed.replace(/[:;,]+$/u, ".");
169}
170
171// Assemble the first prose paragraph, then keep its first sentence. Lines that
172// the header indents (usage examples, bullet lists) end the paragraph — pulling

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected