UNPKG

react-tinymce-mention

Version:

@Mention functionality for TinyMCE, built with React and Redux.

18 lines (14 loc) 487 B
import twitter from 'twitter-text'; export default function extractMentions(content, delimiter) { let mentions, prop; if (delimiter === '@') { mentions = twitter.extractMentionsWithIndices(content); prop = 'screenName'; } else if (delimiter === '#') { mentions = twitter.extractHashtagsWithIndices(content); prop = 'hashtag'; } else { throw new Error(`Error extracting mentions: ${delimiter} must be either '@' or '#'`); } return { mentions, prop }; }