https://github.com/konforti/truncate
✂️ Truncate long texts by number of lines
https://github.com/konforti/truncate
clamp lines paragraph read-more string text trim truncate
Last synced: 5 months ago
JSON representation
✂️ Truncate long texts by number of lines
- Host: GitHub
- URL: https://github.com/konforti/truncate
- Owner: konforti
- License: mit
- Created: 2018-07-27T13:57:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-18T07:28:51.000Z (almost 8 years ago)
- Last Synced: 2025-08-03T05:45:59.280Z (10 months ago)
- Topics: clamp, lines, paragraph, read-more, string, text, trim, truncate
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ✂️ Truncate long texts by number of lines
## ✨ Features
- Truncate text by number of lines.
- Truncate form end, start or middle.
- Custom ellipsis.
## 🔧 Installation
```bash
npm i -S @konforti/truncate
```
```bash
yarn add @konforti/truncate
```
## ✏️ Usage
```js
import truncate from '@konforti/truncate';
const res = truncate(
longTextWrapper,
longText, // default "".
lines, // default 1.
truncFrom, // default "end".
ellipsis, // default "...".
wrapperOffset // default 5
);
```
## 🔖 Types Definition
```js
function truncate(
longTextWrapper: HTMLElement,
longText: string
lines: number
truncFrom: 'start' | 'middle' | 'end'
ellipsis: string
wrapperOffset: number
): {text: string, truncated: boolean} {}
```