Home /code /A JavaScript implementation of Twitter's text processing library /

A JavaScript implementation of Twitter's text processing library

2:17 am, April 23, 2017

Original Post Date: 11:10 pm, July 21, 2014

Looks interesting and provides text processing, url extraction hashtag and user name processing.

A JavaScript utility that provides text processing routines for Tweets. This library conforms to a common test suite shared by many other implementations, particularly twitter-text.gem (Ruby). The library provides autolinking and extraction for URLs, usernames, lists, and hashtags.

https://github.com/twitter/twitter-text-js 

Extraction Examples

// basic extraction
var usernames = twttr.txt.extractMentions("Mentioning @twitter and @jack")
// usernames == ["twitter", "jack"]

Auto-linking Examples

twttr.txt.autoLink("link @user, please #request");

twttr.txt.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
          ]
        }
    ]});

See Tweet Entities for more info getting url entities from Twitter's API.