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

34 lines
552 B
TypeScript
Raw Normal View History

/**
* Emoji
*/
import { emojiRegex } from "./emoji.regex";
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;
name?: string;
2018-06-17 19:55:39 +09:00
};
export default function(text: string) {
const name = text.match(/^:([a-zA-Z0-9+_-]+):/);
if (name) {
return {
type: 'emoji',
content: name[0],
name: name[1]
} as TextElementEmoji;
}
const unicode = text.match(emojiRegex);
if (unicode) {
const [content, emoji] = unicode;
return {
type: 'emoji',
content,
emoji
} as TextElementEmoji;
}
return null;
2018-06-17 19:55:39 +09:00
}