How to use the twitter-text.getTweetLength function in twitter-text

To help you get started, we’ve selected a few twitter-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pixeldesu / surfbird / src / twitter / actions.js View on Github external
ipcMain.on('surfbird:send:tweet', function (e, tweet) {
  var tweetLength = twittxt.getTweetLength(tweet.text)
  if (tweetLength > 140 && tweet.media.length > 0) {
    e.sender.send('surfbird:hook:nosup:tweet')
  }
  else if (tweetLength > 140) {
    var tweetid = tweet.id
    var tweets = []

    // split the tweet into chunks
    var chunks = tweet.text.split(' ').filter(function (it) {
      return it.length > 0
    })

    // calculate mentions
    var mentionsLength = 0
    var mentions = [] // NOTE: Not using twitter-text function because we only want leading tweets.
    while (chunks.length) {
github sillygwailo / Slack-Twitter / slack-twitter.js View on Github external
require(__dirname + '/plugins/filter/' + file);
      });
      filters = require(__dirname + '/plugins/filters.js').filters;
      filters.forEach(function(filter) {
        text = filter.execute(text);
      });
      if (TwitterText.getTweetLength(text) <= 140) {
        T.post('statuses/update', { status: text }, function(error, data, response) {
          if (error) {
            console.log('Posting tweet error: ' + error);
          }
        });
      }
      else {
        channel = rtm.dataStore.getChannelById(message.channel);
        web.chat.postMessage(channel.id, "The tweet was too long! Character count: " + TwitterText.getTweetLength(message.text), function(err, res) {
          if (err) {
            console.log('Error:', err);
          } else {
            console.log('Message sent: ', res);
          }
        });
        channel = null;
      } // If message longer than 140 character
    });
  } // Message type.
github DefinitelyTyped / DefinitelyTyped / types / twitter-text / twitter-text-tests.ts View on Github external
} else if (isCashtagEntity(e)) {
        console.log("cashtag: ", e.cashtag);
    } else {
        console.error("Unreachable");
    }
    console.log(`indices: (${e.indices[0]}, ${e.indices[1]})`);
}

let result: string;
result = twitter.autoLink(text);
result = twitter.autoLinkUsernamesOrLists(text);
result = twitter.autoLinkHashtags(text);
result = twitter.autoLinkCashtags(text);
result = twitter.autoLinkUrlsCustom(text, {targetBlank: true, suppressNoFollow: true});

const len: number = twitter.getTweetLength(text);

const linked: string = twitter.autoLink("link @user, and expand url... http://t.co/0JG5Mcq", {
    urlEntities: [
        {
            url: "http://t.co/0JG5Mcq",
            display_url: "blog.twitter.com/2011/05/twitte…",
            expanded_url: "http://blog.twitter.com/2011/05/twitter-for-mac-update.html",
            indices: [
                30,
                48
            ]
        }
    ]});

const usernames: string[] = twitter.extractMentions("Mentioning @twitter and @jack");
github sillygwailo / Slack-Twitter / slack-twitter.js View on Github external
fs.readdir(__dirname + '/plugins/filter', function (error, files) {
      text = message.text;
      files.forEach(function (file) {
        require(__dirname + '/plugins/filter/' + file);
      });
      filters = require(__dirname + '/plugins/filters.js').filters;
      filters.forEach(function(filter) {
        text = filter.execute(text);
      });
      if (TwitterText.getTweetLength(text) <= 140) {
        T.post('statuses/update', { status: text }, function(error, data, response) {
          if (error) {
            console.log('Posting tweet error: ' + error);
          }
        });
      }
      else {
        channel = rtm.dataStore.getChannelById(message.channel);
        web.chat.postMessage(channel.id, "The tweet was too long! Character count: " + TwitterText.getTweetLength(message.text), function(err, res) {
          if (err) {
            console.log('Error:', err);
          } else {
            console.log('Message sent: ', res);
          }
        });
        channel = null;
github bigcompany / resources / twitter / index.js View on Github external
function tweetLength (options, callback) {
  var l = require('twitter-text').getTweetLength(options.message);

  if (callback) {
    callback(null, l);
  }
  else {
    return l;
  }
};
github pixeldesu / surfbird / app / _js / vue / compose.vue View on Github external
characterCount (e) {
      var remain = 140 - (twitter.getTweetLength($('.js-compose-tweet').val()) % 140)
      var chains = Math.floor(twitter.getTweetLength($('.js-compose-tweet').val()) / 140)

      if ($('.js-compose-tweet').val().length > 0) {
        $('.js-compose-tweet-btn').attr('disabled', false)
      } else {
        $('.js-compose-tweet-btn').attr('disabled', true)
      }

      $('.js-remaining-character-count').text(remain).css('marginLeft', (chains > 0 ? 0 : '10px'))
      if(chains > 0) {
        $('.js-chained-tweets').text('(' + chains.toString() + ')').css('display', 'inline')
      } else {
        $('.js-chained-tweets').css('display', 'none')
      }
    },
    sendMessage (e) {
github shprink / ionic-angular-twitter-pwa / src / pages / tweet / tweet.ts View on Github external
      .map(({ tweet }) => this.maxCharacter - getTweetLength(tweet));
  }
github crcastle / serverless-buffer-app-gui / src / components / ScheduleTweet.vue View on Github external
charactersLeft: function() {
      if (this.newTweet.length == 0) return 140
      return 140 - twttr.getTweetLength(this.newTweet)
    },
    isTooLong: function() {
github vanita5 / birdknife / libs / birdknife-delimiter.js View on Github external
updateExplicitCount: function(status, withMedia) {
        this.explicit_count = twitter.getTweetLength(status) + (withMedia ? 24 : 0);
    },
github pixeldesu / surfbird / app / _js / vue / compose.vue View on Github external
characterCount (e) {
      var remain = 140 - (twitter.getTweetLength($('.js-compose-tweet').val()) % 140)
      var chains = Math.floor(twitter.getTweetLength($('.js-compose-tweet').val()) / 140)

      if ($('.js-compose-tweet').val().length > 0) {
        $('.js-compose-tweet-btn').attr('disabled', false)
      } else {
        $('.js-compose-tweet-btn').attr('disabled', true)
      }

      $('.js-remaining-character-count').text(remain).css('marginLeft', (chains > 0 ? 0 : '10px'))
      if(chains > 0) {
        $('.js-chained-tweets').text('(' + chains.toString() + ')').css('display', 'inline')
      } else {
        $('.js-chained-tweets').css('display', 'none')
      }
    },
    sendMessage (e) {