thelounge/client/js/helpers/ircmessageparser/findEmoji.ts
Max Leiter dd05ee3a65
TypeScript and Vue 3 (#4559)
Co-authored-by: Eric Nemchik <eric@nemchik.com>
Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
2022-06-18 17:25:21 -07:00

26 lines
451 B
TypeScript

import emojiRegExp from "emoji-regex";
import {Part} from "./merge";
const regExp = emojiRegExp();
export type EmojiPart = Part & {
emoji: string;
};
function findEmoji(text: string) {
const result: EmojiPart[] = [];
let match: RegExpExecArray | null;
while ((match = regExp.exec(text))) {
result.push({
start: match.index,
end: match.index + match[0].length,
emoji: match[0],
});
}
return result;
}
export default findEmoji;