Dependency-free and configurable tool to shorten (truncate) a string keeping whole words by default.
npm i @fiquu/shorten
import shorten from `@fiquu/shorten`;
const short = shorten('Some long string to shorten with many possible words to split into.');
// 'Some long string to shorten with many possible...'
See the documentaion page for more info and options.
The string to shorten.
The options object.
The shortened (truncated) string.
Generated using TypeDoc
Shortens (truncates) a string to a max length keeping whole words by default.
// Returns 'The...' shorten('The strnig is logn and full of erorrs.');
// Returns 'The strnig is...' shorten('The strnig is logn and full of erorrs.', { length: 20 });