2022-01-18 08:06:16 -06:00
|
|
|
export const unicodeEmojiCategories = ['face', 'people', 'animals_and_nature', 'food_and_drink', 'activity', 'travel_and_places', 'objects', 'symbols', 'flags'] as const;
|
|
|
|
|
|
|
|
export type UnicodeEmojiDef = {
|
2019-09-21 07:31:38 -05:00
|
|
|
name: string;
|
|
|
|
keywords: string[];
|
|
|
|
char: string;
|
2022-01-18 08:06:16 -06:00
|
|
|
category: typeof unicodeEmojiCategories[number];
|
|
|
|
}
|
|
|
|
|
|
|
|
// initial converted from https://github.com/muan/emojilib/commit/242fe68be86ed6536843b83f7e32f376468b38fb
|
2022-07-13 07:17:19 -05:00
|
|
|
import _emojilist from '../emojilist.json';
|
|
|
|
|
2022-07-13 07:39:16 -05:00
|
|
|
export const emojilist = _emojilist as UnicodeEmojiDef[];
|
2022-12-25 00:52:52 -06:00
|
|
|
|
2023-01-31 20:25:13 -06:00
|
|
|
const _indexByChar = new Map<string, number>();
|
|
|
|
const _charGroupByCategory = new Map<string, string[]>();
|
|
|
|
emojilist.forEach((emo, i) => {
|
|
|
|
_indexByChar.set(emo.char, i);
|
|
|
|
|
|
|
|
if (_charGroupByCategory.has(emo.category)) {
|
|
|
|
_charGroupByCategory.get(emo.category)?.push(emo.char);
|
|
|
|
} else {
|
|
|
|
_charGroupByCategory.set(emo.category, [emo.char]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export const emojiCharByCategory = _charGroupByCategory;
|
|
|
|
|
2022-12-25 00:52:52 -06:00
|
|
|
export function getEmojiName(char: string): string | undefined {
|
2023-01-31 20:25:13 -06:00
|
|
|
const idx = _indexByChar.get(char);
|
|
|
|
if (typeof idx === 'undefined') {
|
|
|
|
return undefined;
|
|
|
|
} else {
|
|
|
|
return emojilist[idx].name;
|
|
|
|
}
|
2022-12-25 00:52:52 -06:00
|
|
|
}
|