Truncator
Layout specific text truncator considering line length, content height or character length.
Installation
You can install truncator from npm.
$ npm install truncator --save
If you are using module loader such as Rollup or Webpack:
;
Also, you can use it from unpkg:
<!-- Normal build --><!-- Minified build -->
var truncate = Truncatortruncate;
Usage
Just call truncate
function then the specified text will be truncated.
var truncator = ;
el
:HTMLElement
that will be inputtext
.text
: Truncate targetstring
.options
: Truncate optionsobject
.line
,height
orcount
ellipsis
: Ellipsis symbol.null
indicates no symbol will be added. default:'...'
The returned object has the following methods:
recalc()
: Retry to truncate the initially givenel
andtext
on the current state. It is useful if you want to adapt resizing the container element.restoreText()
: Restore the original text onel
.
// Re-truncate the texttruncator; // Restore the original texttruncator;
Example
var el = document;var truncator = ; window;
License
MIT