3.0.2 • Published 9 months ago

tweet-truncator v3.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 months ago

tweet-truncator Actions Status: test

Truncate contents to 280 chars for tweeting.

Installation

npm install tweet-truncator

Usage

truncate(content, options)

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/

TweetTruncator

TweetTruncator is a core class of tweet-truncator.

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.

3.0.2

9 months ago

3.0.1

12 months ago

2.0.0

3 years ago

1.0.4

8 years ago

1.0.3

8 years ago