twitter-text-tweetlength-js

subset of official twitter-text library dedicated to counting tweet length

Usage no npm install needed!

<script type="module">
  import twitterTextTweetlengthJs from 'https://cdn.skypack.dev/twitter-text-tweetlength-js';
</script>

README

Build Status npm Bower

twitter-text-tweetlength-js

This library is a subset of official twitter-text library dedicated to counting tweet length. Autolinking, extraction and other officially-implemented features were all removed.

NPM Users

Install it with: npm install twitter-text-tweetlength-js

Usage

The twttr.txt namespace is exported, making it available as such:

Tweet character count example

var twitter = require('twitter-text-tweetlength-js');
twitter.getTweetLength('test.com'); // => 23

getTweetLength returns the computed length of a tweet after taking into consideration t.co URL shortening and non UTF-16 characters

Remaining character count example

var tweet = "This is a test tweet";
var remainingCharacters = 140 - twttr.txt.getTweetLength(tweet);