Truncate contents to 140 chars for Twitter/Tweets
MIT License
Truncate contents to 280 chars for tweeting.
npm install tweet-truncator
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 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);
npm test
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT
Thanks to Tombfix.