Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/awcross/shavette
Truncate text to a specified number of lines
https://github.com/awcross/shavette
ellipsis javascript limit shave text trim truncate
Last synced: about 11 hours ago
JSON representation
Truncate text to a specified number of lines
- Host: GitHub
- URL: https://github.com/awcross/shavette
- Owner: awcross
- License: mit
- Created: 2018-04-15T18:45:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-21T05:53:32.000Z (almost 6 years ago)
- Last Synced: 2024-11-08T21:41:15.266Z (11 days ago)
- Topics: ellipsis, javascript, limit, shave, text, trim, truncate
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# shavette [![Build Status](https://travis-ci.org/awcross/shavette.svg?branch=master)](https://travis-ci.org/awcross/shavette)
> Truncate text to a specified number of lines
Using [shave](https://github.com/dollarshaveclub/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
```html
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.
``````js
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](https://github.com/dollarshaveclub/shave#syntax) 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](https://alexcross.io)