hippofish/packages/client/src/scripts/emojilist.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

import data from "unicode-emoji-json/data-by-group.json";
import emojiComponents from "unicode-emoji-json/data-emoji-components.json";
2023-06-30 06:34:09 +02:00
import individualData from "unicode-emoji-json/data-by-emoji.json";
import keywordSet from "emojilib";
import { defaultStore } from "@/store";
2023-09-02 01:27:33 +02:00
export interface UnicodeEmojiDef {
emoji: string;
2024-03-30 16:30:03 +01:00
category: (typeof unicodeEmojiCategories)[number]["name"];
category_slug: (typeof unicodeEmojiCategories)[number]["slug"];
skin_tone_support: boolean;
slug: string;
keywords?: string[];
2023-09-02 01:27:33 +02:00
}
2024-03-30 16:30:03 +01:00
export const unicodeEmojiCategories = data.map((categories) => ({
slug: categories.slug,
name: categories.name,
}));
export function addSkinTone(emoji: string, skinTone?: number) {
const chosenSkinTone = skinTone || defaultStore.state.reactionPickerSkinTone;
const skinToneModifiers = [
2023-06-24 06:22:44 +02:00
"",
emojiComponents.light_skin_tone,
emojiComponents.medium_light_skin_tone,
emojiComponents.medium_skin_tone,
emojiComponents.medium_dark_skin_tone,
emojiComponents.dark_skin_tone,
];
2023-06-30 06:34:09 +02:00
const strippedEmoji = emoji.replace(
new RegExp(`(${skinToneModifiers.slice(1).join("|")})`, "gi"),
"",
);
if (individualData[strippedEmoji].skin_tone_support) {
return strippedEmoji + (skinToneModifiers[chosenSkinTone - 1] || "");
} else {
return emoji;
}
}
2024-03-30 16:30:03 +01:00
export const emojilist: UnicodeEmojiDef[] = data
.flatMap((category) =>
category.emojis.map((emoji) => ({
...emoji,
category: category.name,
category_slug: category.slug,
keywords: keywordSet[emoji.emoji],
})),
)
.map((item) => ({
emoji: item.emoji,
slug: item.slug,
category: item.category,
category_slug: item.category_slug,
skin_tone_support: item.skin_tone_support || false,
keywords: item.keywords || [],
}));