mirror of
https://github.com/thelounge/thelounge
synced 2024-11-23 12:33:07 +00:00
dd05ee3a65
Co-authored-by: Eric Nemchik <eric@nemchik.com> Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
25 lines
451 B
TypeScript
25 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;
|