Socket
Socket
Sign inDemoInstall

tweetparser.js

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tweetparser.js

Small javascript library that parse an element containing a tweet and turn URLS, @user & #hashtags into working urls


Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Install size
55.4 kB
Created
Weekly downloads
 

Readme

Source

tweetParser.js - demo

Parse Twitter Usernames, Hashtags and URLs tweetParser.js Parse elements containing a tweets and turn URLS, @users & #hashtags into working urls

tweetParser is also available as a Django Template Filter

PARAMETERS
ParametersTypedefaultdescription
urlClassStringtweet_linkcss Class used for url in the tweet
userClassStringtweet_usercss Class used for @user profil url in the tweet
hashtagClassStringhashtagcss Class used for hashtags url in the tweet
targetHTML attribute for anchor tags_blanktarget used for all generated
searchWithHashtagsBooleantruegenerate hashtag link, if true : "twitter.com/hashtag/", if false : "twitter.com/search?q="
ParseUsersBooleantruewill parse @users if is set to true
parseUrlsBooleantruewill parse URLS if is set to true
parseHashtagsBooleantruewill parse hashtags if is set to true
INITIALISATION
You can install tweetParser.js with Bower

if you want to use bower just type :

bower install tweetparser.js
Or via npm
npm install --save-dev tweetparser.js
Add tweetParser.min.js to your HTML document
    <script src="js/tweetParser.min.js"></script>
Your tweet in your html document
    <p class="tweet">This is my awesome text only tweet ! #web #twitter @twitter http://www.twitter.com/ !!</p>
getting started with tweetParser
    //basic usage
    tweetParser('.tweet');
    
    //With Default parameters
    tweetParser('.tweet', {
        urlClass : "tweet_link", //this is default
        userClass : "tweet_user", //this is default
        hashtagClass : "hashtag", //this is default
        target : "_blank", //this is default
        searchWithHashtags : true //this is default
        parseUsers : true,
        parseHashtags : true,
        parseUrls : true
    });
    
    // Note that '.tweet' is your own CSS selector
Want to use it in the jQuery way ?
  <script src="path/to/jquery.min.js"></script>
  <script src="path/to/tweetParser.js"></script>

and call tweetParser like in v1 :

$([SELECTOR]).tweetParser([PARAMETERS]);
RESULT EXAMPLE
Check out the demo

you can customize your tweet with css classes used in parameters

Result After parsing tweets

Contributing

  • Give it a star !
  • Report a bug
  • Tweet about it :)
Pull Requests
  • Solve a problem
  • For code enhancement, use JSLint as a code quality tool.
  • Small is better than Big.
Changelog
  • v2.2.0

    • Add Babel in dev dependecies
    • Port dev code to es6 syntax
  • v2.1.3

    • Fix #10 - target link parameter issue
  • v2.1.2

    • Emojis support
  • v2.1.1

    • resolve issue #9 - Wrap tweetParser and the jQuery compatibility file in the same file.
  • v2.1.0

    • Add a jQuery compatibility file.
    • You can now use Both VanillaJS or jQuery.
    <!-- To use it with jQuery : add tweetParser.js and jquery.tweetParser.js -->
    <script src="dist/tweetParser.js"></script>
    <script src="dev/jquery.tweetParser.js"></script>
    

    and call tweetParser like in v1 :

    $([SELECTOR]).tweetParser([PARAMETERS]);
    

    It is always easier to use it without jQuery just don't add jquery.tweetParser.js and :

    tweetParser([SELECTOR], [PARAMETERS]);
    
  • v2.0.2

    • Code refactoring
  • v2.0.1

    • Fix issue #8 - is now Firefox compatible - replace innerText by textContent
  • v2.0.0

    • REMOVE jQuery dependecies...
    • ...But it still easy to use it as simple as a jQuery Plugin.
    • Improve URL regex : white spaces are not eaten anymore

NB : For you, there is just some small changes in the syntax to call tweetParser.

use

tweetParser([SELECTOR], [PARAMETERS]);

instead of :

$([SELECTOR]).tweetParser([PARAMETERS]);
  • v1.3.1

    • Remove Gruntfile to switch to gulpfile
    • Prepare to publish to npm
    • Improve the Demo
    • Add sourcemaps
  • v1.3.0

    • Improve (one more time) URL regex :raised_hands:
  • v1.2.1

    • Better URL regex
  • v1.2.0

    • add parameter parseUsers, parseHashtags, parseUrls
    • Makeover on the demo
    • JSLint passed
  • v1.1.0

    • searchWithHashtags parameter added

      You can now choose where hashtags links will point to. when searchWithHastags = true (default), tweetParser will generate the following link for each hashtags : "twitter.com/hashtag/THE_HASHTAG".
      if you set it to false, the link will be : "twitter.com/search?q=THE_HASHTAG"

    • code optimisation, remove useless var.

  • v1.0.0

    Initial Version

Keywords

FAQs

Last updated on 01 Dec 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc