Skip to content

Core API

The tokenize function is framework-agnostic and can be used without React.

import emojiMartData from '@emoji-mart/data';
import { fromEmojiMart } from 'react-emoji-text/adapters/emoji-mart';
import { tokenize } from 'react-emoji-text/core';
const data = fromEmojiMart(emojiMartData);
const tokens = tokenize('hello :wave: world', { data });
// [
// { type: 'text', value: 'hello ' },
// { type: 'emoji', emoji: {...}, native: '👋', source: 'shortcode', ... },
// { type: 'text', value: ' world' },
// ]
[
  {
    "type": "text",
    "value": "hello "
  },
  {
    "type": "emoji",
    "native": "👋",
    "shortcode": "wave",
    "match": ":wave:",
    "source": "shortcode"
  },
  {
    "type": "text",
    "value": " world "
  },
  {
    "type": "emoji",
    "native": "🙂",
    "match": ":)",
    "source": "ascii"
  },
  {
    "type": "text",
    "value": " "
  },
  {
    "type": "unknown",
    "shortcode": "missing",
    "match": ":missing:"
  }
]
OptionTypeDefaultDescription
dataEmojiDatarequiredEmoji dataset
customEmojisCustomEmojiCategory[]Custom emoji categories
asciibooleantrueMatch ASCII emoticons
defaultSkinSkinToneDefault skin tone
extraAliasesRecord<string, string>Additional shortcode mappings
type Token = TextToken | EmojiToken | UnknownToken;
type TextToken = {
type: 'text';
value: string;
};

Plain text between emoji matches.

type EmojiToken = {
type: 'emoji';
emoji: EmojiEntry;
native: string;
skin?: SkinTone;
shortcode?: string;
match: string;
source: 'unicode' | 'shortcode' | 'ascii' | 'custom';
};
FieldDescription
emojiFull emoji entry from the dataset
nativeResolved native Unicode string
skinApplied skin tone (if any)
shortcodeThe matched shortcode (for shortcode/custom sources)
matchThe original matched text in the input
sourceHow the emoji was matched
type UnknownToken = {
type: 'unknown';
shortcode: string;
match: string;
};

Shortcodes that look like :name: but don’t match any known emoji.