mizzkey/src/mfm/parse/elements/emoji.ts

21 lines
336 B
TypeScript
Raw Normal View History

/**
* Emoji
*/
2018-06-17 19:55:39 +09:00
export type TextElementEmoji = {
2018-11-03 22:38:12 +09:00
type: 'emoji';
content: string;
emoji: string;
2018-06-17 19:55:39 +09:00
};
export default function(text: string) {
2018-11-04 17:36:37 +09:00
const match = text.match(/^:([a-zA-Z0-9+_-]+):/);
if (!match) return null;
const emoji = match[0];
return {
type: 'emoji',
content: emoji,
2018-08-15 20:27:49 +09:00
emoji: match[1]
2018-06-17 19:55:39 +09:00
} as TextElementEmoji;
}