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 committed by Eugen Rochko
parent 9d94b32448
commit 33d58fb936

View File

@ -60,12 +60,14 @@ interface SkinTone {
skin_tone?: EmojiSkin; skin_tone?: EmojiSkin;
} }
type RawEmoji = BaseEmoji &
CustomEmoji &
Pick<Emoji, 'skin_variations'> &
Pick<PickerProps, 'custom'> &
SkinTone;
function sanitize( function sanitize(
emoji: BaseEmoji & emoji: RawEmoji,
CustomEmoji &
Pick<Emoji, 'skin_variations'> &
Pick<PickerProps, 'custom'> &
SkinTone,
): ):
| 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 */
} }