21 lines
356 B
TypeScript
Raw Normal View History

/**
* Emoji
*/
2018-06-17 19:55:39 +09:00
export type TextElementEmoji = {
2018-06-18 14:28:43 +09:00
type: 'emoji'
2018-06-17 19:55:39 +09:00
content: string
emoji: string
};
export default function(text: string) {
const match = text.match(/^:[a-zA-Z0-9+-_]+:/);
if (!match) return null;
const emoji = match[0];
return {
type: 'emoji',
content: emoji,
emoji: emoji.substr(1, emoji.length - 2)
2018-06-17 19:55:39 +09:00
} as TextElementEmoji;
}