mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-10 12:16:23 +01: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
9d94b32448
commit
33d58fb936
@ -60,12 +60,14 @@ interface SkinTone {
|
|||||||
skin_tone?: EmojiSkin;
|
skin_tone?: EmojiSkin;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sanitize(
|
type RawEmoji = BaseEmoji &
|
||||||
emoji: BaseEmoji &
|
|
||||||
CustomEmoji &
|
CustomEmoji &
|
||||||
Pick<Emoji, 'skin_variations'> &
|
Pick<Emoji, 'skin_variations'> &
|
||||||
Pick<PickerProps, 'custom'> &
|
Pick<PickerProps, 'custom'> &
|
||||||
SkinTone,
|
SkinTone;
|
||||||
|
|
||||||
|
function sanitize(
|
||||||
|
emoji: RawEmoji,
|
||||||
):
|
):
|
||||||
| BaseEmoji
|
| BaseEmoji
|
||||||
| (Omit<CustomEmoji, 'short_names'> & Pick<PickerProps, 'custom'>) {
|
| (Omit<CustomEmoji, 'short_names'> & Pick<PickerProps, 'custom'>) {
|
||||||
@ -109,27 +111,17 @@ function sanitize(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSanitizedData(
|
type GetDataArgs = [
|
||||||
...args: [
|
|
||||||
emoji: BaseEmoji | string,
|
|
||||||
skin: EmojiSkin | null,
|
|
||||||
set?:
|
|
||||||
| 'apple'
|
|
||||||
| 'google'
|
|
||||||
| 'twitter'
|
|
||||||
| 'facebook'
|
|
||||||
| 'emojione'
|
|
||||||
| 'messenger',
|
|
||||||
]
|
|
||||||
) {
|
|
||||||
return sanitize(getData(...args));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getData(
|
|
||||||
emoji: BaseEmoji | string,
|
emoji: BaseEmoji | string,
|
||||||
skin: EmojiSkin | null,
|
skin: EmojiSkin | null,
|
||||||
set?: 'apple' | 'google' | 'twitter' | 'facebook' | 'emojione' | 'messenger',
|
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 @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 */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
let emojiData: any = {};
|
let emojiData: any = {};
|
||||||
@ -199,11 +191,7 @@ function getData(
|
|||||||
emojiData.unified = emojiData.variations.shift();
|
emojiData.unified = emojiData.variations.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
return emojiData as BaseEmoji &
|
return emojiData as RawEmoji;
|
||||||
CustomEmoji &
|
|
||||||
Pick<Emoji, 'skin_variations'> &
|
|
||||||
Pick<PickerProps, 'custom'> &
|
|
||||||
SkinTone;
|
|
||||||
|
|
||||||
/* 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 */
|
/* 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…
x
Reference in New Issue
Block a user