Split a string in to sentences. Supports multiple languages.
npm install string-segmenter- Splits strings into sentences.
- Supports multiple languages.
- Respects common abbreviations (Mr., Mrs., Etc.) to avoid incorrect sentence
splits (English & Spanish only currently).
``sh`
npm install string-segmenter
`js
import { splitBySentence } from "string-segmenter"
const text = "Dr. John Smith, Jr. gave a lecture. It was insightful."
const sentences = []
for (const { segment } of splitBySentence(text)) {
sentences.push(segment.trim())
}
console.log(sentences)
// Output: ["Dr. John Smith, Jr. gave a lecture.", "It was insightful."]
`
Splits the input string into sentences.
- input: The string to be split.locale
- : The locale to be used for sentence segmentation. Defaults to "en".
Clears the cache of Intl.Segmenter instances.
`sh`
npm run build
`sh
npm test # once
npm run dev # run and watch for file changes
``
Contributions are welcome! Please open an issue or submit a pull request.