1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-17 16:18:27 +09:00
cherrypick/packages/frontend/src/scripts/emojilist.ts
YS 2a41f6c383
enhance: Unicode絵文字名逆引き効率化 (#9757)
* Unicode絵文字名前取得を連想配列で行う

* Unicode絵文字事前カテゴリ集計

* Mapを使用

* Update packages/frontend/src/scripts/emojilist.ts

Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>

---------

Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
2023-02-01 11:25:13 +09:00

37 lines
1.1 KiB
TypeScript

export const unicodeEmojiCategories = ['face', 'people', 'animals_and_nature', 'food_and_drink', 'activity', 'travel_and_places', 'objects', 'symbols', 'flags'] as const;
export type UnicodeEmojiDef = {
name: string;
keywords: string[];
char: string;
category: typeof unicodeEmojiCategories[number];
}
// initial converted from https://github.com/muan/emojilib/commit/242fe68be86ed6536843b83f7e32f376468b38fb
import _emojilist from '../emojilist.json';
export const emojilist = _emojilist as UnicodeEmojiDef[];
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;
export function getEmojiName(char: string): string | undefined {
const idx = _indexByChar.get(char);
if (typeof idx === 'undefined') {
return undefined;
} else {
return emojilist[idx].name;
}
}