Extract mentions (@mention) and/or hashtags (#hashtag) from any text
const extract = require('mention-hashtag')
const mentions = extract('Any text with @mention');
// mentions == ['@mention']
const hashtags = extract('Any text with #hashtag', '#');
// hashtags == ['#hashtag']
const all = extract('Any text with #hashtag and @mention and @othermention', 'all');
// all == { mentions: ['@mention', '@othermention'], hashtags: ['#hashtag'] }
NOTE: The extract of mentions is by default. For extract hashtags, the '#' symbol in second parameter is required.
const mentions = extract('Any text with @mention and @mention and @othermention', { unique: true });
// mentions == ['@mention', '@othermention']
const hashtags = extract('Any text with #hashtag and #hashtag and #otherhashtag', { unique: true, type: '#' });
// hashtags == ['#hashtag', '#otherhashtag']
const all = extract('Any text with #hashtag and #hashtag and @mention and @mention', { unique: true, type: 'all' });
// all == { mentions: ['@mention'], hashtags: ['#hashtag'] }
NOTE: The symbol '#' is communicated in 'type' property of second parameter
const mentions = extract('Any text with @mention and @othermention', { symbol: false });
// mentions == ['mention', 'othermention']
const hashtags = extract('Any text with #hashtag and #otherhashtag', { symbol: false, type: '#' });
// hashtags == ['hashtag', 'otherhashtag']
const all = extract('Any text with #hashtag and @mention', { symbol: false, type: 'all' });
// all == { mentions: ['mention'], hashtags: ['hashtag'] }
const mentions = extract('Any text with @mention and @mention and @othermention', { symbol: false, unique: true });
// mentions == ['mention', 'othermention']
const hashtags = extract('Any text with #hashtag and #hashtag and #otherhashtag', { symbol: false, unique: true, type: '#' });
// hashtags == ['hashtag', 'otherhashtag']
const all = extract('Any text with #hashtag and #hashtag and @mention and @mention', { symbol: false, unique: true, type: 'all' });
// all == { mentions: ['mention'], hashtags: ['hashtag'] }
$ npm install && npm test
MIT © lmfresneda