thelounge/client/js/helpers/ircmessageparser/findEmoji.ts

26 lines
427 B
TypeScript
Raw Normal View History

2022-05-15 00:18:06 +02:00
import emojiRegExp from "emoji-regex";
import {Part} from "./merge";
2017-08-23 16:19:04 +02:00
2022-05-15 00:18:06 +02:00
const regExp = emojiRegExp();
function findEmoji(text: string) {
const result: EmojiPart[] = [];
2017-08-23 16:19:04 +02:00
let match;
2022-05-15 00:18:06 +02:00
while ((match = regExp.exec(text))) {
2017-08-23 16:19:04 +02:00
result.push({
start: match.index,
end: match.index + match[0].length,
emoji: match[0],
2017-08-23 16:19:04 +02:00
});
}
return result;
}
2022-05-15 00:18:06 +02:00
export type EmojiPart = Part & {
emoji: string;
};
2019-11-16 18:24:03 +01:00
export default findEmoji;