// Regenerates src/emojiData.ts from the Unicode emoji list (npm: unicode-emoji-json). // node scripts/gen-emoji.mjs // Capped at Emoji 13.1 so every emoji in the picker renders on older Android phones. import { readFileSync, writeFileSync } from 'node:fs'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const groups = require('unicode-emoji-json/data-by-group.json'); const MAX_VERSION = 13.1; const SKIP = new Set(['component']); // skin tone swatches etc. const out = groups .filter((g) => !SKIP.has(g.slug)) .map((g) => ({ name: g.name.replace(' & ', ' and '), // "emoji name" pairs, space-separated words; one string per emoji keeps the file small. emojis: g.emojis.filter((e) => Number.parseFloat(e.emoji_version) <= MAX_VERSION).map((e) => `${e.emoji} ${e.name}`), })); const header = `// Generated by scripts/gen-emoji.mjs from unicode-emoji-json (MIT). Don't edit by hand.\n`; writeFileSync( new URL('../src/emojiData.ts', import.meta.url), `${header}export const EMOJI_GROUPS: { name: string; emojis: string[] }[] = ${JSON.stringify(out)};\n`, ); const count = out.reduce((n, g) => n + g.emojis.length, 0); console.log(`wrote ${count} emoji in ${out.length} groups (${readFileSync(new URL('../src/emojiData.ts', import.meta.url)).length} bytes)`);