From 1b2d0806511613077e36a707f24cae215bfce03f Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 11 Feb 2017 02:32:00 +0900 Subject: Refactoring :sparkles: --- src/common/text/elements/mention.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/common/text/elements/mention.js') diff --git a/src/common/text/elements/mention.js b/src/common/text/elements/mention.js index b58786fd1e..e0fac4dd76 100644 --- a/src/common/text/elements/mention.js +++ b/src/common/text/elements/mention.js @@ -2,16 +2,13 @@ * Mention */ -const regexp = /@[a-zA-Z0-9\-]+/; - -module.exports = { - test: x => new RegExp('^' + regexp.source).test(x), - parse: text => { - const mention = text.match(new RegExp('^' + regexp.source))[0]; - return { - type: 'mention', - content: mention, - username: mention.substr(1) - }; - } +module.exports = text => { + const match = text.match(/^@[a-zA-Z0-9\-]+/); + if (!match) return null; + const mention = match[0]; + return { + type: 'mention', + content: mention, + username: mention.substr(1) + }; }; -- cgit v1.3.1-freya