diff options
| author | YS <47836716+yszkst@users.noreply.github.com> | 2023-02-01 11:25:13 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-01 11:25:13 +0900 |
| commit | 2a41f6c383cc9963aa4a56efafd8dd50abd38709 (patch) | |
| tree | ed08a5a8246bd11b2135845ed264057482f55ad0 /packages/frontend/src/scripts | |
| parent | New Crowdin updates (#9737) (diff) | |
| download | sharkey-2a41f6c383cc9963aa4a56efafd8dd50abd38709.tar.gz sharkey-2a41f6c383cc9963aa4a56efafd8dd50abd38709.tar.bz2 sharkey-2a41f6c383cc9963aa4a56efafd8dd50abd38709.zip | |
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>
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/emojilist.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/packages/frontend/src/scripts/emojilist.ts b/packages/frontend/src/scripts/emojilist.ts index bc52fa7a43..2e853b58b5 100644 --- a/packages/frontend/src/scripts/emojilist.ts +++ b/packages/frontend/src/scripts/emojilist.ts @@ -12,6 +12,25 @@ 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 { - return emojilist.find(emo => emo.char === char)?.name; + const idx = _indexByChar.get(char); + if (typeof idx === 'undefined') { + return undefined; + } else { + return emojilist[idx].name; + } } |