post-entity

Extract entities and text from a post (tweet, status etc)

npm install post-entity
1 downloads in the last week
5 downloads in the last month

post-entity

build status

Extract entities and process a post (tweet, status etc) into text and entity blocks.

Usage

Assume the following:

var pe = require('post-entity'),
    post = 'Hey. This #tweet is @you cos $APPL is at http://apple.com.',

Extract the entities:

var entities = pe.entities(post);

/*
entities =
[ { type: 'hashtag', index: 10, raw: '#tweet' },
  { type: 'mention', index: 20, raw: '@you' },
  { type: 'cashtag', index: 29, raw: '$APPL' },
  { type: 'link', index: 41, raw: 'http://apple.com' } ]
 */

Process into entity/text array:

var result = pe.process(post);

/*
result =
[ { type: 'text', raw: 'Hey. This ', index: 0 },
  { type: 'hashtag', index: 10, raw: '#tweet' },
  { type: 'text', raw: ' is ', index: 16 },
  { type: 'mention', index: 20, raw: '@you' },
  { type: 'text', raw: ' cos ', index: 24 },
  { type: 'cashtag', index: 29, raw: '$APPL' },
  { type: 'text', raw: ' is at ', index: 34 },
  { type: 'link', index: 41, raw: 'http://apple.com' },
  { type: 'text', raw: '.', index: 57 } ]
 */

Install

npm install post-entity

Lisence

MIT

npm loves you