0.0.2 • Published 11 years ago

post-entity v0.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
11 years ago

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