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/url.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/common/text/elements/url.js') diff --git a/src/common/text/elements/url.js b/src/common/text/elements/url.js index d02aef0800..f350b707ac 100644 --- a/src/common/text/elements/url.js +++ b/src/common/text/elements/url.js @@ -2,15 +2,12 @@ * URL */ -const regexp = /https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+/; - -module.exports = { - test: x => new RegExp('^' + regexp.source).test(x), - parse: text => { - const link = text.match(new RegExp('^' + regexp.source))[0]; - return { - type: 'link', - content: link - }; - } +module.exports = text => { + const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.=\+\-]+/); + if (!match) return null; + const link = match[0]; + return { + type: 'link', + content: link + }; }; -- cgit v1.3.1-freya