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:
parent
ca30b5b3ef
commit
5735e09738
1 changed files with 16 additions and 28 deletions
|
@ -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 */
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue