Skip to main content

Function: findEmoji()

findEmoji(text): Readonly<{ emoji: string; position: number; shortcode: string; }> | null

Defined in: packages/lexical-emoji-extension/src/findEmoji.ts:78

Finds emoji shortcodes in text by scanning for potential start positions. The canonical short names such as "😃" are matched even if they are at the end of the text, but a text such as ":)" is only matched if it is followed by a space or non-letter character.

Parameters

text

string

Returns

Readonly<{ emoji: string; position: number; shortcode: string; }> | null

Examples

assert(findEmoji(":man-facepalming:").emoji === "🤦‍♂️");
const input = "handles :) mid-string";
const result = findEmoji(input);
assert(result.position === "handles ".length);
assert(result.shortcode === ":)")
assert(result.emoji === "🙂");
assert([
input.slice(0, result.position),
result.emoji,
input.slice(result.position + result.shortcode.length)
].join("") === "handles 🙂 mid-string");
assert(findEmoji(":)") === null)