a cache for slack profile pictures and emojis
1import { emojilib } from "./slack_emoji_map.json";
2
3/**
4 * Interface representing emoji metadata
5 */
6interface EmojiData {
7 /** The emoji name/shortcode */
8 name: string;
9 /** Unicode codepoint for the emoji */
10 unicode: string;
11 /** Unique identifier */
12 id: string;
13 /** Associated keywords/tags */
14 keywords: string[];
15}
16
17/**
18 * Maps emoji names to their Unicode codepoints
19 */
20class EmojiMap {
21 private nameToCodepoint: Map<string, string>;
22
23 /**
24 * Creates a new EmojiMap
25 * @param emojiData Array of emoji metadata
26 */
27 constructor(emojiData: EmojiData[]) {
28 this.nameToCodepoint = new Map();
29 for (const emoji of emojiData) {
30 this.nameToCodepoint.set(emoji.name, emoji.unicode);
31 }
32 }
33
34 /**
35 * Gets the Unicode codepoint for an emoji name
36 * @param name The emoji name/shortcode
37 * @returns The Unicode codepoint, or undefined if not found
38 */
39 getCodepoint(name: string): string | undefined {
40 return this.nameToCodepoint.get(name);
41 }
42}
43
44const emojiMap = new EmojiMap(emojilib);
45
46/**
47 * Gets the Slack CDN URL for an emoji
48 * @param keyword The emoji name/shortcode
49 * @returns The CDN URL, or null if emoji not found
50 */
51export function getEmojiUrl(keyword: string): string | null {
52 const codepoint = emojiMap.getCodepoint(keyword);
53 if (!codepoint) return null;
54
55 return `https://a.slack-edge.com/production-standard-emoji-assets/14.0/google-medium/${codepoint.toLowerCase()}.png`;
56}