Repository: discordjs/discord.js
File: packages/formatters/src/formatters.ts (TypeScript)

Code before:
): `<:_:${EmojiId}>` | `<a:_:${EmojiId}>`;

/**
 * Formats an emoji id and name into a fully qualified emoji identifier.
 *
 * @typeParam EmojiId - This is inferred by the supplied emoji id
 * @param emojiId - The emoji id to format
 * @param animated - Whether the emoji is animated
 * @param name - The name of the emoji
 */
export function formatEmoji<EmojiId extends Snowflake, Name extends string>(
	emojiId: EmojiId,
	animated: boolean,
	name: Name,
): `<:${Name}:${EmojiId}>` | `<a:${Name}:${EmojiId}>`;

/**
 * Formats an emoji id and name into a fully qualified emoji identifier.
 *
 * @typeParam FormatEmojiOptions - An options object to format emoji.
 */
export function formatEmoji<EmojiId extends Snowflake, Name extends string>({
	emojiId,
	animated,
	name,
}: Required<FormatEmojiOptions<EmojiId, Name>>): `<:${Name}:${EmojiId}>` | `<a:${Name}:${EmojiId}>`;

export function formatEmoji<EmojiId extends Snowflake, Name extends string>(
	emojiIdOrOptions: EmojiId | FormatEmojiOptions<EmojiId, Name>,
	animated?: boolean,
	name?: Name,
): `<:${string}:${EmojiId}>` | `<a:${string}:${EmojiId}>` {
	const options =
		typeof emojiIdOrOptions === 'object'
			? emojiIdOrOptions
			: {
					emojiId: emojiIdOrOptions,
					name: name ?? '_',
					animated: animated ?? false,
				};

	const { emojiId, animated: isAnimated, name: emojiName } = options;

	return `<${isAnimated ? 'a' : ''}:${emojiName ?? '_'}:${emojiId}>`;
}

/**
 * The options for formatting an emoji
 */
interface FormatEmojiOptions<EmojiId extends Snowflake, Name extends string> {
	/**

Review comment (suggestion):
You can just specify `options`:

```suggestion
export function formatEmoji<EmojiId extends Snowflake, Name extends string>(
	options: Required<FormatEmojiOptions<EmojiId, Name>>,
): `<:${Name}:${EmojiId}>` | `<a:${Name}:${EmojiId}>`;
```

Code after:
): `<:_:${EmojiId}>` | `<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}>`;
}