exuemoji
v2.12.1
Published
Complete Node.js port of the Python emoji library - convert emoji names to unicode and vice versa
Maintainers
Readme
exuemoji
Complete Node.js port of the Python
emojilibrary v2.12.1
Convert emoji names to unicode and vice versa. Supports 14 languages + aliases.
Installation
npm install exuemojiQuick Start
import { emojize, demojize, emojiList, isEmoji } from 'exuemoji';
// Convert emoji names to unicode
emojize('Python is fun :thumbs_up:'); // 'Python is fun 👍'
// Convert unicode to shortcodes
demojize('Python is fun 👍'); // 'Python is fun :thumbs_up:'
// List all emoji in a string
emojiList('Hi 😁'); // [{ emoji: '😁', match_start: 3, match_end: 4 }]
// Check if a string is a single emoji
isEmoji('👍'); // trueAPI Reference
emojize(string, delimiters, variant, language, version, handleVersion)
Replace emoji names (:name:) with unicode characters.
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| string | string | required | Input string with emoji names |
| delimiters | [string, string] | [':', ':'] | Opening/closing delimiters |
| variant | string\|null | null | 'text_type', 'emoji_type', or null |
| language | string | 'en' | Language code or 'alias' |
| version | number\|null | null | Max emoji version |
| handleVersion | string\|Function\|null | null | Handler for emoji above version |
emojize('Hello :thumbs_up:'); // 'Hello 👍'
emojize('Hello {thumbs_up}', ['{', '}']); // 'Hello 👍'
emojize('Hello :+1:', [':', ':'], null, 'alias'); // 'Hello 👍'
emojize(':red_heart:', [':', ':'], 'emoji_type'); // '❤️'
emojize(':thumbs_up:', [':', ':'], null, 'en', 0.5, ''); // '' (filtered out)demojize(string, delimiters, language, version, handleVersion)
Replace unicode emoji with shortcodes.
demojize('Hello 👍'); // 'Hello :thumbs_up:'
demojize('Hello 👍', ['__', '__']); // 'Hello __thumbs_up__'
demojize('Hello 👍', [':', ':'], 'de'); // 'Hello :Daumen_hoch:'
demojize('Hello 👍', [':', ':'], 'alias'); // 'Hello :+1:'analyze(string, nonEmoji, joinEmoji)
Analyze a string and yield tokens for each character/emoji found.
import { analyze, EmojiMatch } from 'exuemoji';
for (const token of analyze('a👍b', true)) {
if (token.value instanceof EmojiMatch) {
console.log('Found emoji:', token.value.emoji);
} else {
console.log('Found char:', token.value);
}
}replaceEmoji(string, replace, version)
Replace emoji with custom strings.
replaceEmoji('Hello 👍 😁', '[emoji]'); // 'Hello [emoji] [emoji]'
replaceEmoji('Hello 👍', (emj, data) => data.en); // 'Hello :thumbs_up:'
replaceEmoji('Hello 👍', '', 0.5); // 'Hello ' (only old emoji)emojiList(string)
Get all emoji in a string with their positions.
emojiList('Hi 😁 there 👍');
// [
// { emoji: '😁', match_start: 3, match_end: 4 },
// { emoji: '👍', match_start: 12, match_end: 13 }
// ]distinctEmojiList(string)
Get unique emoji from a string.
distinctEmojiList('👍 👍 👍 😁'); // ['👍', '😁']emojiCount(string, unique)
Count emoji in a string.
emojiCount('👍 👍 👍'); // 3
emojiCount('👍 👍 👍', true); // 1isEmoji(string)
Check if a string is exactly one RGI emoji.
isEmoji('👍'); // true
isEmoji('hello'); // falsepurelyEmoji(string)
Check if a string contains only emoji (no regular text).
purelyEmoji('👍😁'); // true
purelyEmoji('👍 hello'); // falseversion(string)
Get the Emoji Version of an emoji.
version('😁'); // 0.6
version('👍'); // 0.6
version(':butter:'); // 3.0Supported Languages
| Code | Language |
|------|----------|
| en | English |
| es | Spanish |
| ja | Japanese |
| ko | Korean |
| pt | Portuguese |
| it | Italian |
| fr | French |
| de | German |
| fa | Persian |
| id | Indonesian |
| zh | Chinese |
| ru | Russian |
| tr | Turkish |
| ar | Arabic |
| alias | English aliases (:+1:, etc.) |
Configuration
import { config } from 'exuemoji';
// Keep ZWJ sequences in demojize()
config.demojizeKeepZwj = true; // default
// Keep ZWJ sequences in replaceEmoji()
config.replaceEmojiKeepZwj = false; // defaultBuilding a Bot? See examples/bot-example.js
import { emojize, demojize, isEmoji, emojiCount } from 'exuemoji';
// Discord/Telegram bot example
function processMessage(message) {
// Convert :name: to emoji
const withEmoji = emojize(message);
// Check if message is just emoji
if (isEmoji(message)) {
return `You sent a single emoji: ${message}`;
}
// Count emoji usage
const count = emojiCount(message);
if (count > 5) {
return `Wow, you used ${count} emoji!`;
}
return withEmoji;
}License
BSD-3-Clause (same as original Python emoji library)
