tweet-parser

0.2.0 • Public • Published

tweet-parser

A JS module for parsing tweets into an array of entities.

For example, given a tweet with this content:

Migrating from Angular to React- an honest case study on @songkick by @Jack_Franklin. Watch here- http://bit.ly/2gD80W1  #reactlondon

We get an array of entities:

[
  { type: 'TEXT', content: 'Migrating from Angular to React- an honest case study on ' },
  {
    type: 'USER',
    content: '@songkick',
    url: 'https://www.twitter.com/songkick',
  },
  { type: 'TEXT', content: ' by ' },
  {
    type: 'USER',
    content: '@Jack_Franklin',
    url: 'https://www.twitter.com/Jack_Franklin',
  },
  { type: 'TEXT', content: '. Watch here- ' },
  {
    type: 'LINK',
    content: 'http://bit.ly/2gD80W1',
    url: 'http://bit.ly/2gD80W1',
  },
  { type: 'TEXT', content: '  ' },
  {
    type: 'HASH',
    content: '#reactlondon',
    url: 'https://twitter.com/search?q=%23reactlondon',
  },
]

Why?

A side project I was working on had to render tweets from an API and I wanted a nice way of being able to style different parts of the tweet based on if they were a link, hashtag, user reference or just plain text.

Installation and Usage

$ npm install tweet-parser

$ yarn add tweet-parser
import tweetParser from 'tweet-parser'
 
const result = tweetParser('My fun tweet');
 
console.log(result())
// [ { type: 'TEXT', content: 'My fun tweet' } ]

Readme

Keywords

none

Package Sidebar

Install

npm i tweet-parser

Weekly Downloads

128

Version

0.2.0

License

MIT

Last publish

Collaborators

  • jackfranklin