A small utility to shorten posts to an acceptable tweet-length summary.

Downloads in past


600.2.97 years ago8 years agoMinified + gzip package size for brevity in KB


Build Status
A small utility to count characters, autolink, and shorten posts to an acceptable tweet-length summary.
This is a port of the Python module of the same name. Please refer to for documentation.


With npm, simply npm install brevity.
Otherwise, brevity.js is a single file that can be included anywhere. In the browser, it will define window.brevity with the functions below. `



Find out how many characters a message will use on Twitter with tweetLength():
var brevity = require("brevity");
var length = brevity.tweetLength('Published my first npm and composer packages today!');
console.log(length);  // 99

This text is 119 characters but, due to wrapping, will only use 99 characters.


Convert URLs in plaintext to HTML links.
var brevity = require("brevity");
var html = brevity.autolink("I'm a big fan of (and its creator");

Note that brevity handles parentheses and other punctuation as you'd expect.


The shorten(text) function takes a message of any length and shortens it to a Tweet-length 140 characters, adding an ellipsis at the end of it is truncated. It will not truncate a word or URL in the middle. Shorten takes a few optional parameters that change the way the tweet is formed. Any of these parameters can be null.
  • permalink - included after the ellipsis if and only if the text
is shortened. Must be a URL or false.
  • shortpermalink - included in parentheses at the end of tweets
that are not shortened. Must be a URL or false.
  • shortpermacitation - included in parentheses at the end of tweets
that are not shortened. Must not be a URL, e.g. t4fT2
  • targetLength - The target length for the final text. Defaults to
  • linkLength - The final length of each URL after
shortening. Defaults to 23.
  • formatAsTitle - take the text as a title of a longer
article. Always formats as "Title: $permalink" or "Title… $permalink" if shortened.
var brevity = require("brevity");
var permalink = "";
var longnote = "Brevity ( shortens notes that are too long to fit in a single tweet. It can also count characters to help you make sure your note won't need to be shortened!";
var tweet = brevity.shorten(longnote, permalink);