Refactoring ✨
This commit is contained in:
parent
c20cd97be2
commit
1b2d080651
6 changed files with 52 additions and 68 deletions
|
|
@ -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)
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue