diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-02-11 02:32:00 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-02-11 02:32:00 +0900 |
| commit | 1b2d0806511613077e36a707f24cae215bfce03f (patch) | |
| tree | 1fd3acd227546e5faa7b8ed805e68178bd1e5903 /src/common/text/elements/url.js | |
| parent | Remove variables tracking system to more simply implementation (diff) | |
| download | misskey-1b2d0806511613077e36a707f24cae215bfce03f.tar.gz misskey-1b2d0806511613077e36a707f24cae215bfce03f.tar.bz2 misskey-1b2d0806511613077e36a707f24cae215bfce03f.zip | |
Refactoring :sparkles:
Diffstat (limited to 'src/common/text/elements/url.js')
| -rw-r--r-- | src/common/text/elements/url.js | 19 |
1 files changed, 8 insertions, 11 deletions
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 + }; }; |