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

Code before:
/**
 * The options for formatting an emoji.
 */
interface FormatEmojiOptions<EmojiId extends Snowflake, Name extends string> {
	/**
	 * Whether the emoji is animated
	 */
	animated?: boolean;
	/**
	 * The emoji id to format
	 */
	id: EmojiId;
	/**
	 * The name of the emoji
	 */
	name?: Name;
}

/**
 * Formats a channel link for a direct message channel.
 *
 * @typeParam ChannelId - This is inferred by the supplied channel id
 * @param channelId - The channel's id
 */
export function channelLink<ChannelId extends Snowflake>(
	channelId: ChannelId,
): `https://discord.com/channels/@me/${ChannelId}`;

/**
 * Formats a channel link for a guild channel.
 *
 * @typeParam ChannelId - This is inferred by the supplied channel id
 * @typeParam GuildId - This is inferred by the supplied guild id
 * @param channelId - The channel's id
 * @param guildId - The guild's id
 */
export function channelLink<ChannelId extends Snowflake, GuildId extends Snowflake>(
	channelId: ChannelId,
	guildId: GuildId,
): `https://discord.com/channels/${GuildId}/${ChannelId}`;

export function channelLink<ChannelId extends Snowflake, GuildId extends Snowflake>(
	channelId: ChannelId,
	guildId?: GuildId,
): `https://discord.com/channels/@me/${ChannelId}` | `https://discord.com/channels/${GuildId}/${ChannelId}` {
	return `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`;
}

/**
 * Formats a message link for a direct message channel.
 *

Review comment (suggestion):
```suggestion
 * The options for formatting an emoji.
 *
 * @typeParam EmojiId - This is inferred by the supplied emoji id
 * @typeParam Name - This is inferred by the supplied name
```
Missed these type parameters, oops

Code after:
 * @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;
}

/**
 * Formats a channel link for a direct message channel.
 *
 * @typeParam ChannelId - This is inferred by the supplied channel id
 * @param channelId - The channel's id
 */