1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Refactor emoji utilities by introducing type aliases

This commit introduces type aliases to the emoji utilities in JavaScript code, specifically `RawEmoji` and `GetDataArgs`. These changes help to simplify function signatures. By extracting complex types into separate type aliases, the code readability has been improved significantly.
This commit is contained in:
taichi221228 2024-05-02 13:22:56 +09:00
parent ca30b5b3ef
commit 5735e09738

View file

@ -60,12 +60,14 @@ interface SkinTone {
skin_tone?: EmojiSkin;
}
function sanitize(
emoji: BaseEmoji &
type RawEmoji = BaseEmoji &
CustomEmoji &
Pick<Emoji, 'skin_variations'> &
Pick<PickerProps, 'custom'> &
SkinTone,
SkinTone;
function sanitize(
emoji: RawEmoji,
):
| BaseEmoji
| (Omit<CustomEmoji, 'short_names'> & Pick<PickerProps, 'custom'>) {
@ -109,27 +111,17 @@ function sanitize(
};
}
function getSanitizedData(
...args: [
emoji: BaseEmoji | string,
skin: EmojiSkin | null,
set?:
| 'apple'
| 'google'
| 'twitter'
| 'facebook'
| 'emojione'
| 'messenger',
]
) {
return sanitize(getData(...args));
}
function getData(
type GetDataArgs = [
emoji: BaseEmoji | string,
skin: EmojiSkin | null,
set?: 'apple' | 'google' | 'twitter' | 'facebook' | 'emojione' | 'messenger',
) {
];
function getSanitizedData(...args: GetDataArgs) {
return sanitize(getData(...args));
}
function getData(...[emoji, skin, set]: GetDataArgs) {
/* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
let emojiData: any = {};
@ -199,11 +191,7 @@ function getData(
emojiData.unified = emojiData.variations.shift();
}
return emojiData as BaseEmoji &
CustomEmoji &
Pick<Emoji, 'skin_variations'> &
Pick<PickerProps, 'custom'> &
SkinTone;
return emojiData as RawEmoji;
/* eslint-enable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
}