Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string-segmenter

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-segmenter

Split a string in to sentences. Supports multiple languages.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

String Segmenter

  • Splits strings into sentences.
  • Supports multiple languages.
  • Respects common abbreviations (Mr., Mrs., Etc.) to avoid incorrect sentence splits (English & Spanish only currently).

Installation

npm install string-segmenter

Usage

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."]

API

splitBySentence(input: string, locale: Intl.LocalesArgument = "en"): Iterable<{ segment: string, index: number, input: string }>

Splits the input string into sentences.

  • input: The string to be split.
  • locale: The locale to be used for sentence segmentation. Defaults to "en".

clearSegmenterCache(): void

Clears the cache of Intl.Segmenter instances.

Development

Building the Project

npm run build

Running Tests

npm test # once

npm run dev # run and watch for file changes

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Keywords

FAQs

Package last updated on 10 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc