All files / src/matchers Hashtag.js

100% Statements 5/5
0% Branches 0/1
100% Functions 4/4
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                          2x       404x           166x       371x          
/**
 * @copyright   2016, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
import React from 'react';
import Matcher from '../Matcher';
import Hashtag from '../components/Hashtag';
import { HASHTAG_PATTERN } from '../constants';
 
import type { MatchResponse, HashtagProps } from '../types';
 
const HASHTAG_REGEX = new RegExp(HASHTAG_PATTERN, 'i');
 
export default class HashtagMatcher extends Matcher<Object> {
  replaceWith(match: string, props: Object = {}): React.Element<HashtagProps> {
    return (
      <Hashtag {...props}>{match}</Hashtag>
    );
  }
 
  asTag(): string {
    return 'a';
  }
 
  match(string: string): ?MatchResponse {
    return this.doMatch(string, HASHTAG_REGEX, matches => ({
      hashtagName: matches[1],
    }));
  }
}