mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-25 21:16:43 -06:00
2a41f6c383
* 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>
36 lines
1.1 KiB
TypeScript
36 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;
|
|
}
|
|
}
|