monkeeShark/src/text/parse/elements/mention.ts

18 lines
349 B
TypeScript
Raw Normal View History

2016-12-28 22:49:51 +00:00
/**
* Mention
*/
2018-04-02 04:44:32 +00:00
import parseAcct from '../../../acct/parse';
2016-12-28 22:49:51 +00:00
2017-02-10 17:32:00 +00:00
module.exports = text => {
const match = text.match(/^@[a-z0-9_]+(?:@[a-z0-9\.\-]+[a-z0-9])?/i);
2017-02-10 17:32:00 +00:00
if (!match) return null;
const mention = match[0];
2018-03-27 07:51:12 +00:00
const { username, host } = parseAcct(mention.substr(1));
2017-02-10 17:32:00 +00:00
return {
type: 'mention',
content: mention,
2018-03-27 07:51:12 +00:00
username,
host
2017-02-10 17:32:00 +00:00
};
2016-12-28 22:49:51 +00:00
};