Files
upstream-rocketchat/apps/meteor/app/emoji-native/lib/generateEmojiData.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

153 lines
4.0 KiB
TypeScript

import data from 'emojibase-data/en/data.json';
import emojibaseShortcodes from 'emojibase-data/en/shortcodes/emojibase.json';
import joypixelsShortcodes from 'emojibase-data/en/shortcodes/joypixels.json';
// Map emojibase group numbers to our category keys
const groupToCategory: Record<number, string> = {
0: 'people', // smileys & emotion
1: 'people', // people & body
2: 'people', // component - skin tones etc (we skip these)
3: 'nature', // animals & nature
4: 'food', // food & drink
5: 'travel', // travel & places
6: 'activity', // activities
7: 'objects', // objects
8: 'symbols', // symbols
9: 'flags', // flags
};
export type EmojiEntry = {
name: string;
uc_base: string;
uc_output: string;
uc_match: string;
uc_greedy: string;
shortnames: string[];
category: string;
emojiPackage: string;
unicode: string;
};
function hexFromEmoji(emoji: string): string {
return [...emoji].map((cp) => cp.codePointAt(0)!.toString(16)).join('-');
}
function isRegionalIndicator(hexcode: string): boolean {
if (hexcode.includes('-')) return false;
const cp = parseInt(hexcode, 16);
return cp >= 0x1f1e6 && cp <= 0x1f1ff;
}
function getShortcodes(hexcode: string): string[] {
const entry =
(joypixelsShortcodes as Record<string, string | string[]>)[hexcode] ??
(emojibaseShortcodes as Record<string, string | string[]>)[hexcode];
if (!entry) return [];
return Array.isArray(entry) ? entry : [entry];
}
function buildEmojiData() {
const emojiList: Record<string, EmojiEntry> = {};
const emojisByCategory: Record<string, string[]> = {
people: [],
nature: [],
food: [],
activity: [],
travel: [],
objects: [],
symbols: [],
flags: [],
};
const toneList: Record<string, number> = {};
const bareAliases: [string, string][] = [];
for (const emojiData of data) {
// Skip component group (skin tones, hair styles)
if (emojiData.group === 2) continue;
const isRegional = isRegionalIndicator(emojiData.hexcode);
const category = groupToCategory[emojiData.group ?? -1] ?? (isRegional ? 'flags' : undefined);
if (!category) continue;
const codes = getShortcodes(emojiData.hexcode);
if (codes.length === 0) continue;
const primaryShortcode = codes[0];
const altShortcodes = codes.slice(1).map((s) => `:${s}:`);
const hex = hexFromEmoji(emojiData.emoji);
const bare = emojiData.emoji.replace(/\uFE0F/g, '');
const entry: EmojiEntry = {
name: primaryShortcode,
uc_base: hex,
uc_output: hex,
uc_match: hex,
uc_greedy: hex,
shortnames: altShortcodes,
category,
emojiPackage: 'native',
unicode: emojiData.emoji,
};
const key = `:${primaryShortcode}:`;
emojiList[key] = entry;
if (emojiData.type === 1 && bare !== emojiData.emoji) {
bareAliases.push([bare, key]);
}
// Only add to category if it's NOT a skin tone variant
if (!emojiData.tone && !isRegional) {
emojisByCategory[category].push(primaryShortcode);
}
// Register alternate shortcodes
for (const alt of altShortcodes) {
emojiList[alt] = entry;
}
// Track skin tone support
if (emojiData.skins && emojiData.skins.length > 0) {
toneList[primaryShortcode] = 1;
// Register skin tone variants
for (const skin of emojiData.skins) {
if (!skin.tone) continue;
const tones = Array.isArray(skin.tone) ? skin.tone : [skin.tone];
const skinHex = hexFromEmoji(skin.emoji);
const skinEntry: EmojiEntry = {
name: primaryShortcode,
uc_base: skinHex,
uc_output: skinHex,
uc_match: skinHex,
uc_greedy: skinHex,
shortnames: [],
category,
emojiPackage: 'native',
unicode: skin.emoji,
};
const toneShortcodes = getShortcodes(skin.hexcode);
const fallbackShortcode = `${primaryShortcode}_tone${tones.join('-')}`;
for (const code of [...toneShortcodes, fallbackShortcode]) {
emojiList[`:${code}:`] = skinEntry;
}
}
}
}
return { emojiList, emojisByCategory, toneList, bareAliases };
}
// Build once and cache
let _cached: ReturnType<typeof buildEmojiData> | null = null;
export function getEmojiData() {
if (!_cached) {
_cached = buildEmojiData();
}
return _cached;
}