shavette
v1.1.0
Published
Truncate text to a specified number of lines
Downloads
6
Maintainers
Readme
shavette
Truncate text to a specified number of lines
Using shave, this will truncate text to a maximum number of lines based on the number of DOMRect
objects in an element.
Install
$ npm install shavette --save
Usage
<p class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
</p>
const shavette = require('shavette');
shavette('.content', {
maxLines: 3
});
API
shavette(selector, [options])
Returns the truncated elements.
selector
Type: string
Element
NodeList
The elements to truncate.
options
These options can be passed in addition to the options for shave
.
maxLines
Type: number
Default: 2
The maximum number of lines to truncate the text. If the number of lines is less than maxLines
then the text will not be truncated.
License
MIT © Alex Cross