mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-26 07:23:09 +02:00
c2370a1be6
* chore: Add the SPDX information to each file Add copyright and licensing information as defined in version 3.0 of the REUSE Specification. * tweak format --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
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;
|
|
char: string;
|
|
category: typeof unicodeEmojiCategories[number];
|
|
}
|
|
|
|
// initial converted from https://github.com/muan/emojilib/commit/242fe68be86ed6536843b83f7e32f376468b38fb
|
|
import _emojilist from '../emojilist.json';
|
|
|
|
export const emojilist: UnicodeEmojiDef[] = _emojilist.map(x => ({
|
|
name: x[1] as string,
|
|
char: x[0] as string,
|
|
category: unicodeEmojiCategories[x[2]],
|
|
}));
|
|
|
|
const _indexByChar = new Map<string, number>();
|
|
const _charGroupByCategory = new Map<string, string[]>();
|
|
for (let i = 0; i < emojilist.length; i++) {
|
|
const emo = emojilist[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 | null {
|
|
const idx = _indexByChar.get(char);
|
|
if (idx == null) {
|
|
return null;
|
|
} else {
|
|
return emojilist[idx].name;
|
|
}
|
|
}
|