Truncates text. Prevents embarassing word splices. Truncation + business rules = FUNcation!
npm install legal-ass --save
LegalAss(phrase, options), where
phrase is the string you'd like truncated and
options is an object specifying the following:
|length||(Integer) The maximum number of characters in the truncated return string, including any ellipses string that follows.||Yes|
|splitWords||(Boolean) Should the library truncate in the middle of a word? Defaults to
|ellipses||(String) A string to append to the end of the truncated text. Its length will be factored in to where a string truncates. Defaults to a single-character ellipses (
var LegalAss = ;;// -> 'So this is a story…'
Note that the returned string is only 19 characters long, since a longer string would have split in the middle of the word "all". If you don't care about this, pass
;// -> 'So this is a story al…'
If you'd like to use your own string instead of ellipses, pass that as
;// -> 'So this is a (More >)'
Note that the original phrase above was truncated with a trailing space and the library made the end result an additional character shorter by eliminating it.