smart-text-snippet1.0.0 • Public • Published
Create shortened or chunked text snippets from longer text while leaving sentences intact. Min length is configurable.
Available on npm
npm i smart-text-snippet
var snippets = ;var superLongString = 'I will be a very long string...';var shortSnippet = snippets;// returns the first complete sentence with length at least 150 chars.
Snips the first part of the text with a min length. Returns only complete sentences or the entire input.
var _options =len: 100 // min length of the snippetbreakChars: ' ' '\n' '\r\n' '"' '<' // characters searched for after a stopChar is foundstopChars: '.' '!' '?' // characters used as sentence enders.
returns array of strings
Snips up an large string into smaller strings of snippets of complete sentences. Good for infinite scroll or paging applications.
This module supports multiple module loading systems systems:
- Vanilla browser JS 'dist/smart-text-snippet-browser.js'
- Node style 'dist/smart-text-snippet-node.js' (this is what the npm module exports)
- AMD style 'dist/smart-text-snippet-amd.js'
- Lodash v4 (earlier version may work).
Tests run with node on mocha and chai.