mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
refactor(formatters): Add support for object and name param in formatEmoji() (#10076)
* feat: add support for name param and object in `formatEmoji()` * Update formatters.ts * refactor: swap priority --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -336,11 +336,75 @@ export function formatEmoji<EmojiId extends Snowflake>(
|
||||
animated?: boolean,
|
||||
): `<:_:${EmojiId}>` | `<a:_:${EmojiId}>`;
|
||||
|
||||
export function formatEmoji<EmojiId extends Snowflake>(
|
||||
emojiId: EmojiId,
|
||||
animated = false,
|
||||
): `<:_:${EmojiId}>` | `<a:_:${EmojiId}>` {
|
||||
return `<${animated ? 'a' : ''}:_:${emojiId}>`;
|
||||
/**
|
||||
* Formats a non-animated emoji id and name into a fully qualified emoji identifier.
|
||||
*
|
||||
* @typeParam EmojiId - This is inferred by the supplied emoji id
|
||||
* @typeParam EmojiName - This is inferred by the supplied name
|
||||
* @param options - The options for formatting an emoji
|
||||
*/
|
||||
export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(
|
||||
options: FormatEmojiOptions<EmojiId, EmojiName> & { animated: true },
|
||||
): `<a:${EmojiName}:${EmojiId}>`;
|
||||
|
||||
/**
|
||||
* Formats an animated emoji id and name into a fully qualified emoji identifier.
|
||||
*
|
||||
* @typeParam EmojiId - This is inferred by the supplied emoji id
|
||||
* @typeParam EmojiName - This is inferred by the supplied name
|
||||
* @param options - The options for formatting an emoji
|
||||
*/
|
||||
export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(
|
||||
options: FormatEmojiOptions<EmojiId, EmojiName> & { animated?: false },
|
||||
): `<:${EmojiName}:${EmojiId}>`;
|
||||
|
||||
/**
|
||||
* Formats an emoji id and name into a fully qualified emoji identifier.
|
||||
*
|
||||
* @typeParam EmojiId - This is inferred by the supplied emoji id
|
||||
* @typeParam EmojiName - This is inferred by the supplied emoji name
|
||||
* @param options - The options for formatting an emoji
|
||||
*/
|
||||
export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(
|
||||
options: FormatEmojiOptions<EmojiId, EmojiName>,
|
||||
): `<:${EmojiName}:${EmojiId}>` | `<a:${EmojiName}:${EmojiId}>`;
|
||||
|
||||
export function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(
|
||||
emojiIdOrOptions: EmojiId | FormatEmojiOptions<EmojiId, EmojiName>,
|
||||
animated?: boolean,
|
||||
): `<:${string}:${EmojiId}>` | `<a:${string}:${EmojiId}>` {
|
||||
const options =
|
||||
typeof emojiIdOrOptions === 'string'
|
||||
? {
|
||||
id: emojiIdOrOptions,
|
||||
animated: animated ?? false,
|
||||
}
|
||||
: emojiIdOrOptions;
|
||||
|
||||
const { id, animated: isAnimated, name: emojiName } = options;
|
||||
|
||||
return `<${isAnimated ? 'a' : ''}:${emojiName ?? '_'}:${id}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options for formatting an emoji.
|
||||
*
|
||||
* @typeParam EmojiId - This is inferred by the supplied emoji id
|
||||
* @typeParam EmojiName - This is inferred by the supplied emoji name
|
||||
*/
|
||||
export interface FormatEmojiOptions<EmojiId extends Snowflake, EmojiName extends string> {
|
||||
/**
|
||||
* Whether the emoji is animated
|
||||
*/
|
||||
animated?: boolean;
|
||||
/**
|
||||
* The emoji id to format
|
||||
*/
|
||||
id: EmojiId;
|
||||
/**
|
||||
* The name of the emoji
|
||||
*/
|
||||
name?: EmojiName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user