https://github.com/fgribreau/node-truncate
:octopus: Truncate text and keeps urls safe.
https://github.com/fgribreau/node-truncate
javascript truncate truncate-html
Last synced: 3 months ago
JSON representation
:octopus: Truncate text and keeps urls safe.
- Host: GitHub
- URL: https://github.com/fgribreau/node-truncate
- Owner: FGRibreau
- Created: 2013-04-05T12:09:25.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-05-22T19:19:46.000Z (about 2 years ago)
- Last Synced: 2025-03-30T21:12:49.249Z (4 months ago)
- Topics: javascript, truncate, truncate-html
- Language: JavaScript
- Homepage: https://twitter.com/FGRibreau
- Size: 285 KB
- Stars: 53
- Watchers: 2
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
Truncate
==================[](https://github.com/FGRibreau/node-truncate/actions/workflows/ci.yaml) [](https://www.npmjs.com/package/truncate) [](http://bit.ly/2c7uFJq) [](https://twitter.com/FGRibreau) [](https://www.codementor.io/francois-guillaume-ribreau?utm_source=github&utm_medium=button&utm_term=francois-guillaume-ribreau&utm_campaign=github) [](https://join.slack.com/t/fgribreau/shared_invite/zt-edpjwt2t-Zh39mDUMNQ0QOr9qOj~jrg)
Truncate text and keeps urls safe.
## NPM
Install the module with: `npm install truncate`## ❤️ Shameless plug
- [Open-Source self-hostable or fully-managed **webhook as a service**](https://www.hook0.com/)
- [**Charts, simple as a URL**. No more server-side rendering pain, 1 url = 1 chart](https://image-charts.com)
- [Looking for a managed Keycloak IAM ?](https://www.cloud-iam.com/)## Usage
```javascript
// Browser
String.truncate("1234 http://google.com hey :)", 2) === "12…"
``````javascript
// NodeJS
> truncate = require('truncate');
> truncate("1234 http://google.com hey :)", 4);
"1234…"
> truncate("1234 http://google.com hey :)", 4, {ellipsis:null}); // or ellipsis:''
"1234"
> truncate("1234 http://google.com hey :)", 6);
"1234 http://google.com…"
> truncate("1234 http://google.com hey :)", 100);
"1234 http://google.com hey :)"
```## [Changelog](/CHANGELOG.md)
## Donate
I maintain this project in my free time, if it helped you please support my work via [paypal](https://paypal.me/fgribreau) or [bitcoins](https://www.coinbase.com/fgribreau), thanks a lot!
## License
Copyright (c) 2014 Francois-Guillaume Ribreau
Licensed under the MIT license.