https://github.com/yowainwright/truncated.js
Text truncation that doesn't get in the way ✔️ is now called Shave -> npm i shave
https://github.com/yowainwright/truncated.js
Last synced: 11 months ago
JSON representation
Text truncation that doesn't get in the way ✔️ is now called Shave -> npm i shave
- Host: GitHub
- URL: https://github.com/yowainwright/truncated.js
- Owner: yowainwright
- License: mit
- Created: 2016-09-11T02:40:50.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-04-20T20:09:59.000Z (about 6 years ago)
- Last Synced: 2025-02-01T21:03:35.352Z (over 1 year ago)
- Language: HTML
- Homepage: https://dollarshaveclub.github.io/shave/
- Size: 29 MB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/truncated.js)
[](https://github.com/yowainwright/truncated.js)
# Truncated.js
[](https://greenkeeper.io/)
> A plugin for effeciently and semantically truncating text.
This project is now called [**shave**](https://github.com/dollarshaveclub/shave) and is supported [here](https://github.com/dollarshaveclub/shave). ~Thanks
## Setup
```terminal
npm i truncated.js --save-dev
```
or
```terminal
bower i truncated.js --save-dev
```
## Run
1. Add **dist/truncated.js**.
2. `truncate` text within the element you'd like to.
```javascript
truncated('selector', maxHeight);🔥
```
## Basic Examples
**Basic**
```javascript
truncated('selector', maxHeight);
```
**Or Multiples**
```javascript
truncated('selector', maxHeight);
```
**But not this one**
```javascript
truncated('selector:not([not this selector])', maxHeight);
```
**With a special symbol**
```javascript
truncated('selector', maxHeight, {character:'🍻'});
```
**With a special CSS Class**
```javascript
truncated('selector', maxHeight, {character:'🙌', classname:'your-css-class'});
```
**Or with jQuery**
```javascript
$('selector').truncated(maxHeight);
```
## How?
**Truncated.js** trims an element's text string to the last full word that can fit within a specified max height.
## Why?
**Truncated.js** is made for simpicity; it doesn't try to oversolve truncation or provide tons of options. It truncates text to a max height.
## What about the original text?
**Truncated.js** re-adds the _diff_ of the original seleected elements's text in a hidden ``. It runs a check for that `` to make sure text is truncated as desired every time.
## What about size?
**Truncated.js** is small - `~1.5kb` unminified and is meant to do 1 thing - _truncate text to fit beatifully to a specified max height_.
## How can I use it?
You can use **Truncated.js** in all modern formats and as a `jQuery` or `zepto` plugin.