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

18 lines
334 B
TypeScript
Raw Normal View History

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