truncate-middle
There are cases where important information is at the end of the string and truncating the end isn't helpful.
Example use cases
var book1 = "America Again: Re-becoming the Greatness We Never Weren't by Stephen Colbert (978-0446583978)";var truncateMiddle = ;var display = ;// You get 'America Again: Re-becoming the...(978-0446583978)'
Usage
Install from npm
.
npm install --save truncate-middle
Requiring in JavaScript
var truncateMiddle = ;;// Result:// 'the q...own'
Defaults:
;// Result:// 'the quick brown'
Specifying a front length of 5:
;// Result:// 'the q…'
Specifying a front length of 5 and back length of 3:
;// Result:// 'the q…own'
When there isn't anything to truncate:
;// Result:// 'the quick brown'
Function signature
- str (string): String to be truncated
- frontLen (number): Number of characters to be remained in front.
- backLen (number): Number of characters to be remained at the back.
- truncateStr (string): String that is replaced the truncated portion. Defaults to
…
Return is always the truncated string.
License
MIT