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,
|
2017-11-15 07:35:15 +01:00
|
|
|
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;
|