A small library that truncates a string. It can insert or append an ellipsis at any desired position of the truncated result.
npm install smart-truncateSmart Truncate  
=========
A small library that truncates a string. It can insert or append an ellipsis (or a custom mark) at any desired position of the truncated result.
npm install --save smart-truncate
js
smartTruncate(string, length[, options])
`
#### Paramaters
>_string_
A string with a minimum length of 4 characters.>_length_
The length of the truncated result.
>_options_
>_options.position_
Optional. The index of the ellipsis (zero based). Default is at the end.
>_options.mark_
Optional. The character[s] indicating omission. Default is an ellipsis "…".
#### Return value
>A new string truncated with an ellipsis or custom mark.
Usage
`js
const smartTruncate = require('smart-truncate');const string = 'To iterate is human, to recurse divine.';
// Append an ellipsis at the end of the truncated string.
const truncated = smartTruncate(string, 15);
`Output:
"To iterate is …"*
`js
const string = 'To iterate is human, to recurse divine.';// Insert an ellipsis in the middle of a smart truncated string.
const truncated = smartTruncate(string, 21, {position: 10});
`Output:
"To iterate…se divine."*
`js
const files = [
'1Password 6.app',
'Adobe',
'Adobe Creative Cloud',
'Adobe Illustrator CC 2015.3',
'Adobe Photoshop CC 2014',
'Adobe Photoshop CC 2015.5',
'App Store.app'
];const truncated = files.map((filename) => smartTruncate(filename, 21, {position: 10}));
`Output:
`js
[
'1Password 6.app',
'Adobe',
'Adobe Creative Cloud',
'Adobe Illu… CC 2015.3',
'Adobe Phot…op CC 2014',
'Adobe Phot… CC 2015.5',
'App Store.app'
]
`Tests
npm test`In lieu of a formal style guide, take care to maintain the existing coding style. Add tests for any new or changed functionality. Lint and test your code.