2022-01-18 23:06:16 +09: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 21:31:38 +09:00
|
|
|
name: string;
|
|
|
|
char: string;
|
2022-01-18 23:06:16 +09:00
|
|
|
category: typeof unicodeEmojiCategories[number];
|
|
|
|
}
|
|
|
|
|
|
|
|
// initial converted from https://github.com/muan/emojilib/commit/242fe68be86ed6536843b83f7e32f376468b38fb
|
2022-07-13 21:17:19 +09:00
|
|
|
import _emojilist from '../emojilist.json';
|
|
|
|
|
2023-05-30 11:18:40 +09:00
|
|
|
export const emojilist: UnicodeEmojiDef[] = _emojilist.map(x => ({
|
|
|
|
name: x[1] as string,
|
|
|
|
char: x[0] as string,
|
|
|
|
category: unicodeEmojiCategories[x[2]],
|
|
|
|
}));
|
2022-12-25 15:52:52 +09:00
|
|
|
|
2023-02-01 11:25:13 +09:00
|
|
|
const _indexByChar = new Map<string, number>();
|
|
|
|
const _charGroupByCategory = new Map<string, string[]>();
|
2023-05-30 11:18:40 +09:00
|
|
|
for (let i = 0; i < emojilist.length; i++) {
|
|
|
|
const emo = emojilist[i];
|
2023-02-01 11:25:13 +09:00
|
|
|
_indexByChar.set(emo.char, i);
|
|
|
|
|
|
|
|
if (_charGroupByCategory.has(emo.category)) {
|
|
|
|
_charGroupByCategory.get(emo.category)?.push(emo.char);
|
|
|
|
} else {
|
|
|
|
_charGroupByCategory.set(emo.category, [emo.char]);
|
|
|
|
}
|
2023-05-30 11:18:40 +09:00
|
|
|
}
|
2023-02-01 11:25:13 +09:00
|
|
|
|
|
|
|
export const emojiCharByCategory = _charGroupByCategory;
|
|
|
|
|
2023-06-01 16:28:24 +09:00
|
|
|
export function getEmojiName(char: string): string | null {
|
2023-02-01 11:25:13 +09:00
|
|
|
const idx = _indexByChar.get(char);
|
2023-06-01 16:28:24 +09:00
|
|
|
if (idx == null) {
|
|
|
|
return null;
|
2023-02-01 11:25:13 +09:00
|
|
|
} else {
|
|
|
|
return emojilist[idx].name;
|
|
|
|
}
|
2022-12-25 15:52:52 +09:00
|
|
|
}
|