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.
$ npm install shavette --save
<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
});
Returns the truncated elements.
Type: string
Element
NodeList
The elements to truncate.
These options can be passed in addition to the options for shave
.
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.
MIT © Alex Cross