All files / src/matchers Email.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 34 35 36                          2x       1102x           422x       973x                
/**
 * @copyright   2016, Miles Johnson
 * @license     https://opensource.org/licenses/MIT
 * @flow
 */
 
import React from 'react';
import Matcher from '../Matcher';
import Email from '../components/Email';
import { EMAIL_PATTERN } from '../constants';
 
import type { MatchResponse, EmailProps } from '../types';
 
const EMAIL_REGEX = new RegExp(EMAIL_PATTERN, 'i');
 
export default class EmailMatcher extends Matcher<Object> {
  replaceWith(match: string, props: Object = {}): React.Element<EmailProps> {
    return (
      <Email {...props}>{match}</Email>
    );
  }
 
  asTag(): string {
    return 'a';
  }
 
  match(string: string): ?MatchResponse {
    return this.doMatch(string, EMAIL_REGEX, matches => ({
      emailParts: {
        username: matches[1],
        host: matches[2],
      },
    }));
  }
}