truncate-sentences
v2.0.0
Published
[![Travis CI](https://img.shields.io/travis/AnandChowdhary/truncate-sentences.svg)](https://travis-ci.org/AnandChowdhary/truncate-sentences) [![Coverage Status](https://coveralls.io/repos/github/AnandChowdhary/truncate-sentences/badge.svg?branch=master&v=
Downloads
6
Readme
🤏 Truncate Sentences
A Node.js package to simply truncate a paragraph to complete sentences. It uses Natural under the hood to tokenize sentences.
For example, truncate("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ipsum eros, scelerisque id volutpat nec, lobortis quis ipsum. Nullam at diam felis. Sed vitae iaculis sem. Duis scelerisque vehicula malesuada. Nullam sodales eget tortor tincidunt faucibus.", 200)
will return the first few sentences until reaching 200 characters: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ipsum eros, scelerisque id volutpat nec, lobortis quis ipsum. Nullam at diam felis. Sed vitae iaculis sem.
instead of simply truncating a string and adding ellipses.
⭐ Usage
Add the dependency from NPM:
npm install truncate-sentences
Truncate a paragraph:
import truncate from "truncate-sentences";
truncate(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ipsum eros, scelerisque id volutpat nec, lobortis quis ipsum. Nullam at diam felis. Sed vitae iaculis sem. Duis scelerisque vehicula malesuada. Nullam sodales eget tortor tincidunt faucibus.",
200
);
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ipsum eros, scelerisque id volutpat nec, lobortis quis ipsum. Nullam at diam felis. Sed vitae iaculis sem.
If the first sentence is already longer than the limit, it adds an ellipsis (...
) at the end.
🛠️ Development
Install dependencies:
npm install
Compile Typescript to ES6 before publishing to NPM:
npm run build
📝 License
MIT