A comprehensive TypeScript library for emoji utilities including intelligent text-to-emoji replacement, fast search, flag conversion, and emoji lookup functions.
โจ Smart Text Replacement โ Convert natural language to emojis with contextual awareness
๐ Emoji Search (new!) โ Ranked results with exact/partial matching, category filters, limits
๐ Emoji Lookup โ Find emojis by name, shortname, or get random selections
๐ณ๏ธ Flag Conversion โ Convert between country codes and flag emojis
๐ค Letter Conversion โ Transform letters to regional indicator emojis
โก High Performance โ Optimized algorithms with configurable options
๐ฏ TypeScript Support โ Full type definitions
# npm
npm install easy-emojis
# yarn
yarn add easy-emojis
# pnpm
pnpm add easy-emojisimport * as EasyEmojis from 'easy-emojis';
// Lookup
EasyEmojis.getEmoji('pizza'); // ๐
EasyEmojis.getEmoji(':coffee:'); // โ
// NEW: Search
EasyEmojis.searchEmojis('apple')[0]?.emoji.emoji; // ๐ (top match)
// Flags & Letters
EasyEmojis.countryCodeToFlag('JP'); // ๐ฏ๐ต
EasyEmojis.letterToEmoji('S'); // ๐ธRanked search with optional category filtering, strict (exact) mode, and result limits.
import { searchEmojis } from 'easy-emojis';
const results = searchEmojis('apple');
/*
[
{ emoji: { ...๐ }, score: 100, matchType: 'exact' },
{ emoji: { ...๐ }, score: 78, matchType: 'partial' },
...
]
*/
// Just the emoji characters:
const chars = results.map(r => r.emoji.emoji); // ["๐","๐",...]- Searches match names (e.g.,
"red apple") and shortnames (without colons), e.g."apple". - Exact matches on name/shortname score 100.
searchEmojis('tada'); // treats shortname; exact if it matches ๐searchEmojis('red apple', { exactMatch: true });
// returns only exact name/shortname matches (score = 100)import { getSearchCategories, searchEmojis } from 'easy-emojis';
const categories = getSearchCategories(); // ["People & Body (family)", "Food & Drink (food-sweet)" ...]
const food = searchEmojis('cake', { category: 'Food & Drink (food-sweet)' });Tip: Use
getSearchCategories()to present a category dropdown and pass the selected value tosearchEmojis.
searchEmojis('face', { limit: 10 });- Exact match (name or shortname) โ
score = 100,matchType: 'exact'. - Partial match โ
score โ [60..90], higher if the match occurs earlier in the text.- Name partials are prioritized over shortname partials.
- Secondary sort by shorter name length to bias simpler names when scores tie.
- Empty or whitespaceโonly queries throw:
Error("Search query cannot be empty").
import * as EasyEmojis from 'easy-emojis';
// Get random emoji
EasyEmojis.getRandomEmoji(); // e.g. "๐"
// Lookup by name or shortname
EasyEmojis.getEmojiByName('red apple'); // "๐"
EasyEmojis.getEmojiByShortName(':apple:'); // "๐"
// Universal lookup (accepts both)
EasyEmojis.getEmoji('red apple'); // "๐"
EasyEmojis.getEmoji(':apple:'); // "๐"import * as EasyEmojis from 'easy-emojis';
EasyEmojis.countryCodeToFlag('US'); // "๐บ๐ธ"
EasyEmojis.flagToCountryCode('๐บ๐ธ'); // "US"
EasyEmojis.letterToEmoji('S'); // "๐ธ"
EasyEmojis.emojiToLetter('๐ธ'); // "S"Transform your text with intelligent emoji replacements! Perfect for social media, chat apps, and creative content.
import { replaceTextWithEmojis } from 'easy-emojis';
const result = replaceTextWithEmojis("I love pizza and coffee!");
console.log(result.text); // "I โค๏ธ ๐ and โ!"import {
replaceTextSubtle, // Conservative
replaceTextBalanced, // Moderate
replaceTextExpressive, // Aggressive
replaceTextSmart // Context-aware
} from 'easy-emojis';
const text = "Having a great morning with coffee and friends!";
replaceTextSubtle(text); // "Having a great morning with โ and friends!"
replaceTextBalanced(text); // "Having a great morning with โ and friends!"
replaceTextExpressive(text); // "Having a great ๐
with โ and friends!"
replaceTextSmart(text); // Context-aware replacements based on sentimentimport { replaceTextWithEmojis, EmojiReplaceMode } from 'easy-emojis';
const result = replaceTextWithEmojis("I love programming and pizza", {
mode: EmojiReplaceMode.MODERATE,
confidenceThreshold: 0.8,
maxReplacements: 3,
categories: ['food', 'emotion', 'tech'],
customMappings: {
programming: { emoji: '๐ป', confidence: 0.9, category: 'tech' }
}
});
console.log(result.text); // "I โค๏ธ๐ป and ๐"
console.log(result.stats);
// {
// totalReplacements: 3,
// averageConfidence: 0.9,
// categoriesUsed: ['emotion', 'tech', 'food']
// }| Mode | Description | Use Case |
|---|---|---|
CONSERVATIVE |
High-confidence, minimal replacements | Professional communication |
MODERATE |
Balanced approach with good coverage | Social media posts |
AGGRESSIVE |
Maximum replacements, lower threshold | Creative content, casual chat |
CONTEXTUAL |
AI-powered context analysis | Smart assistants, adaptive UX |
interface EmojiReplaceOptions {
mode: EmojiReplaceMode;
confidenceThreshold: number;
maxReplacements?: number;
preserveCase?: boolean;
categories?: string[];
customMappings?: object;
}interface EmojiReplaceResult {
text: string;
replacements: EmojiReplacement[];
originalText: string;
stats: {
totalReplacements: number;
averageConfidence: number;
categoriesUsed: string[];
};
}| Function | Description | Example |
|---|---|---|
getRandomEmoji() |
Returns a random emoji | ๐ฒ |
getEmojiByName(name) |
Find emoji by name | getEmojiByName('pizza') โ ๐ |
getEmojiByShortName(shortname) |
Find by shortname | getEmojiByShortName(':pizza:') โ ๐ |
getEmoji(query) |
Universal lookup (name or shortname) | getEmoji('pizza') โ ๐ |
| Function | Description | Example |
|---|---|---|
searchEmojis(query, options?) |
Ranked search across names & shortnames | searchEmojis('apple', { limit: 10 }) |
getSearchCategories() |
List available categories (sorted) | getSearchCategories() โ string[] |
SearchOptions
type SearchOptions = {
limit?: number; // default 50
category?: string; // exact category string
exactMatch?: boolean; // only exact matches when true
};SearchResult
type SearchResult = {
emoji: Emoji;
score: number; // 100 exact; 60โ90 partial
matchType: 'exact' | 'partial';
};| Function | Description | Example |
|---|---|---|
countryCodeToFlag(code) |
Country code โ flag | countryCodeToFlag('JP') โ ๐ฏ๐ต |
flagToCountryCode(flag) |
Flag โ country code | flagToCountryCode('๐ฏ๐ต') โ JP |
letterToEmoji(letter) |
Letter โ regional indicator | letterToEmoji('A') โ ๐ฆ |
emojiToLetter(emoji) |
Regional indicator โ letter | emojiToLetter('๐ฆ') โ A |
| Function | Description |
|---|---|
replaceTextWithEmojis(text, options) |
Advanced replacement with full control |
replaceTextSubtle(text) |
Conservative preset |
replaceTextBalanced(text) |
Moderate preset |
replaceTextExpressive(text) |
Aggressive preset |
replaceTextSmart(text) |
Context-aware preset |
import { searchEmojis } from 'easy-emojis';
function suggest(query: string) {
if (!query.trim()) return [];
return searchEmojis(query, { limit: 8 }).map(r => ({
char: r.emoji.emoji,
name: r.emoji.name,
shortname: r.emoji.shortname,
score: r.score
}));
}const post = "Just finished an amazing workout! Time for coffee and relaxation.";
const enhanced = replaceTextBalanced(post);
// "Just finished an amazing workout! Time for โ and relaxation."const message = "Good morning! Having breakfast - eggs and coffee";
const fun = replaceTextExpressive(message);
// "๐
! Having breakfast - ๐ฅ and โ"const subject = "Meeting tomorrow - pizza lunch provided";
const professional = replaceTextSubtle(subject);
// "Meeting tomorrow - ๐ lunch provided"- โก Fast: O(N) scoring over the (optionally filtered) dataset, plus a single sort on the result set
- ๐ Memory efficient: Smart data shapes and minimal overhead
- ๐ฆ Lightweight: Tree-shakeable ES modules
- ๐ฏ Scalable: Handles large texts efficiently
# Clone the repository
git clone https://github.com/sinansonmez/easy-emojis.git
# Install dependencies
npm install
# Run tests
npm run test
# Build the project
npm run buildnpm run testMIT ยฉ Sinan Chaush
- vNext โ Added
searchEmojis()andgetSearchCategories()with ranked results, exact/partial matching, category filters, and result limits.