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

sentence-splitter

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sentence-splitter

split {japanese, english} text into sentences.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-69.33%
Maintainers
1
Weekly downloads
 
Created
Source

sentence-splitter

Split {Japanese, English} text into sentences.

Installation

npm install sentence-splitter

Usage

  • splitSentences(text, [options]): Node[]
import splitSentences from "sentence-splitter";
let sentences = splitSentences("text.\n\ntext");
console.log(JSON.stringify(sentences, null, 4));
/*
[
    {
        "type": "Sentence",
        "raw": "text.",
        "loc": {
            "start": {
                "line": 1,
                "column": 0
            },
            "end": {
                "line": 1,
                "column": 5
            }
        },
        "range": [
            0,
            5
        ]
    },
    {
        "type": "WhiteSpace",
        "raw": "\n",
        "loc": {
            "start": {
                "line": 1,
                "column": 5
            },
            "end": {
                "line": 2,
                "column": 0
            }
        },
        "range": [
            5,
            6
        ]
    },
    {
        "type": "WhiteSpace",
        "raw": "\n",
        "loc": {
            "start": {
                "line": 2,
                "column": 0
            },
            "end": {
                "line": 3,
                "column": 0
            }
        },
        "range": [
            6,
            7
        ]
    },
    {
        "type": "Sentence",
        "raw": "text",
        "loc": {
            "start": {
                "line": 3,
                "column": 0
            },
            "end": {
                "line": 3,
                "column": 4
            }
        },
        "range": [
            7,
            11
        ]
    }
]
*/

// with splitting char options
let sentences = splitSentences("text¶text", {
    charRegExp: /¶/
});
sentences.length; // 2
  • line: start with 1
  • column: start with 0

See more detail on Why do line of location in JavaScript AST(ESTree) start with 1 and not 0?

Node's type

  • Sentence: Sentence Node contain punctuation.
  • WhiteSpace: WhiteSpace Node has \n.

Tests

npm test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

Keywords

FAQs

Package last updated on 15 Nov 2015

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