# tweet-truncator

> Truncate contents of tweet to 140 chars.

Latest version **3.0.2** (published 2023-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install tweet-truncator
pnpm add tweet-truncator
yarn add tweet-truncator
bun add tweet-truncator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2023-08-22 |
| First published | 2015-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | azu |
| Maintainers | azu |
| Keywords | twitter, truncate, length |

## Links

- npm: https://www.npmjs.com/package/tweet-truncator
- Repository: https://github.com/azu/tweet-truncator
- Issues: https://github.com/azu/tweet-truncator/issues
- npm.io page: https://npm.io/package/tweet-truncator

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^4.3.4
- [twitter-text](https://npm.io/package/twitter-text.md) ^3.1.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 3.0.2 (latest) — 2023-08-22
- 3.0.1 — 2023-05-27
- 2.0.0 — 2021-03-27
- 1.0.4 — 2015-12-25
- 1.0.3 — 2015-12-24

## README

# tweet-truncator [![Actions Status: test](https://github.com/azu/tweet-truncator/workflows/test/badge.svg)](https://github.com/azu/tweet-truncator/actions?query=workflow%3A"test")

Truncate contents to 280 chars for tweeting.

- [twitter-text-js](https://github.com/twitter/twitter-text/tree/master/js)

## Installation

    npm install tweet-truncator

## Usage

### truncate(content, [options])

```js
import { truncate } from "tweet-truncator";
const contents = {
    title: "tweet-truncator",
    url: "https://github.com/azu/tweet-truncator",
    desc: "Truncate contents to 140 chars.",
    quote: "quote",
    tags: ["#twitter", "JavaScript"]
};
const options = {
    defaultPrefix: "See:",
    template: '%desc% "%title%" %url% %tags%',
    // maxLength: 280
};
const result = truncate(contents, options);
console.log(result);
/*
Truncate contents to 140 chars. "tweet-truncator" https://github.com/azu/tweet-truncator #twitter #JavaScript
*/
```

See [example/](example/)

#### [TweetTruncator](src/tweet-truncator.js)

TweetTruncator is a core class of tweet-truncator.

```js
const truncator = new TweetTruncator({
    defaultPrefix: "See:",
    template: `%desc% "%title%" %url% %tags%`
});
const contents = {
    title: "TITLE",
    url: "https://github.com/twitter/twitter-text",
    desc: "",
    quote: "quote",
    tags: []
};
const overLength = 10;// it means that remove 10 chars from contents.
var result = truncator.truncateStatus(contents, overLength);
```

## Tests

    npm test

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## License

MIT

Thanks to [Tombfix](https://github.com/tombfix/core "Tombfix").

---
_Source: https://npm.io/package/tweet-truncator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
