Extract entities and text from a post (tweet, status etc)
JavaScript
Latest commit 6482ea5 Apr 29, 2013 @phuu Release 0.0.2
Permalink
Failed to load latest commit information.
lib Initial commit. Apr 29, 2013
test
.travis.yml Add travis. Apr 29, 2013
README.md Add travis. Apr 29, 2013
index.js Initial commit. Apr 29, 2013
package.json Release 0.0.2 Apr 29, 2013

README.md

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