dd05ee3a65
Co-authored-by: Eric Nemchik <eric@nemchik.com> Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
26 lines
451 B
TypeScript
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;
|