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/mention.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/mention.js')
| -rw-r--r-- | src/common/text/elements/mention.js | 21 |
1 files changed, 9 insertions, 12 deletions
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) + }; }; |