@discordjs/formatters
Advanced tools
Comparing version 1.0.0-dev.1690416583-8f4256d.0 to 1.0.0-dev.1732752782-e89c6b66a
@@ -176,50 +176,58 @@ import { URL } from 'node:url'; | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\n\`\`\``; | ||
declare function codeBlock<Content extends string>(content: Content): `\`\`\`\n${Content}\n\`\`\``; | ||
/** | ||
* Wraps the content inside a code block with the specified language. | ||
* | ||
* @typeParam L - This is inferred by the supplied language | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Language - This is inferred by the supplied language | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param language - The language for the code block | ||
* @param content - The content to wrap | ||
*/ | ||
declare function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\n\`\`\``; | ||
declare function codeBlock<Language extends string, Content extends string>(language: Language, content: Content): `\`\`\`${Language}\n${Content}\n\`\`\``; | ||
/** | ||
* Wraps the content inside \`backticks\` which formats it as inline code. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function inlineCode<C extends string>(content: C): `\`${C}\``; | ||
declare function inlineCode<Content extends string>(content: Content): `\`${Content}\``; | ||
/** | ||
* Formats the content into italic text. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function italic<C extends string>(content: C): `_${C}_`; | ||
declare function italic<Content extends string>(content: Content): `_${Content}_`; | ||
/** | ||
* Formats the content into bold text. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function bold<C extends string>(content: C): `**${C}**`; | ||
declare function bold<Content extends string>(content: Content): `**${Content}**`; | ||
/** | ||
* Formats the content into underscored text. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
* @deprecated Use {@link underline} instead. | ||
*/ | ||
declare function underscore<C extends string>(content: C): `__${C}__`; | ||
declare function underscore<Content extends string>(content: Content): `__${Content}__`; | ||
/** | ||
* Formats the content into underlined text. | ||
* | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function underline<Content extends string>(content: Content): `__${Content}__`; | ||
/** | ||
* Formats the content into strike-through text. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function strikethrough<C extends string>(content: C): `~~${C}~~`; | ||
declare function strikethrough<Content extends string>(content: Content): `~~${Content}~~`; | ||
/** | ||
@@ -229,6 +237,6 @@ * Formats the content into a quote. | ||
* @remarks This needs to be at the start of the line for Discord to format it. | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function quote<C extends string>(content: C): `> ${C}`; | ||
declare function quote<Content extends string>(content: Content): `> ${Content}`; | ||
/** | ||
@@ -238,13 +246,13 @@ * Formats the content into a block quote. | ||
* @remarks This needs to be at the start of the line for Discord to format it. | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function blockQuote<C extends string>(content: C): `>>> ${C}`; | ||
declare function blockQuote<Content extends string>(content: Content): `>>> ${Content}`; | ||
/** | ||
* Wraps the URL into `<>` which stops it from embedding. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param url - The URL to wrap | ||
*/ | ||
declare function hideLinkEmbed<C extends string>(url: C): `<${C}>`; | ||
declare function hideLinkEmbed<Content extends string>(url: Content): `<${Content}>`; | ||
/** | ||
@@ -259,21 +267,21 @@ * Wraps the URL into `<>` which stops it from embedding. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to display | ||
* @param url - The URL the content links to | ||
*/ | ||
declare function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`; | ||
declare function hyperlink<Content extends string>(content: Content, url: URL): `[${Content}](${string})`; | ||
/** | ||
* Formats the content and the URL into a masked URL. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam U - This is inferred by the supplied URL | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @typeParam Url - This is inferred by the supplied URL | ||
* @param content - The content to display | ||
* @param url - The URL the content links to | ||
*/ | ||
declare function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`; | ||
declare function hyperlink<Content extends string, Url extends string>(content: Content, url: Url): `[${Content}](${Url})`; | ||
/** | ||
* Formats the content and the URL into a masked URL with a custom tooltip. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam T - This is inferred by the supplied title | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @typeParam Title - This is inferred by the supplied title | ||
* @param content - The content to display | ||
@@ -283,9 +291,9 @@ * @param url - The URL the content links to | ||
*/ | ||
declare function hyperlink<C extends string, T extends string>(content: C, url: URL, title: T): `[${C}](${string} "${T}")`; | ||
declare function hyperlink<Content extends string, Title extends string>(content: Content, url: URL, title: Title): `[${Content}](${string} "${Title}")`; | ||
/** | ||
* Formats the content and the URL into a masked URL with a custom tooltip. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam U - This is inferred by the supplied URL | ||
* @typeParam T - This is inferred by the supplied title | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @typeParam Url - This is inferred by the supplied URL | ||
* @typeParam Title - This is inferred by the supplied title | ||
* @param content - The content to display | ||
@@ -295,38 +303,45 @@ * @param url - The URL the content links to | ||
*/ | ||
declare function hyperlink<C extends string, U extends string, T extends string>(content: C, url: U, title: T): `[${C}](${U} "${T}")`; | ||
declare function hyperlink<Content extends string, Url extends string, Title extends string>(content: Content, url: Url, title: Title): `[${Content}](${Url} "${Title}")`; | ||
/** | ||
* Formats the content into a spoiler. | ||
* | ||
* @typeParam C - This is inferred by the supplied content | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function spoiler<C extends string>(content: C): `||${C}||`; | ||
declare function spoiler<Content extends string>(content: Content): `||${Content}||`; | ||
/** | ||
* Formats a user id into a user mention. | ||
* | ||
* @typeParam C - This is inferred by the supplied user id | ||
* @typeParam UserId - This is inferred by the supplied user id | ||
* @param userId - The user id to format | ||
*/ | ||
declare function userMention<C extends Snowflake>(userId: C): `<@${C}>`; | ||
declare function userMention<UserId extends Snowflake>(userId: UserId): `<@${UserId}>`; | ||
/** | ||
* Formats a channel id into a channel mention. | ||
* | ||
* @typeParam C - This is inferred by the supplied channel id | ||
* @typeParam ChannelId - This is inferred by the supplied channel id | ||
* @param channelId - The channel id to format | ||
*/ | ||
declare function channelMention<C extends Snowflake>(channelId: C): `<#${C}>`; | ||
declare function channelMention<ChannelId extends Snowflake>(channelId: ChannelId): `<#${ChannelId}>`; | ||
/** | ||
* Formats a role id into a role mention. | ||
* | ||
* @typeParam C - This is inferred by the supplied role id | ||
* @typeParam RoleId - This is inferred by the supplied role id | ||
* @param roleId - The role id to format | ||
*/ | ||
declare function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>`; | ||
declare function roleMention<RoleId extends Snowflake>(roleId: RoleId): `<@&${RoleId}>`; | ||
/** | ||
* Formats a role id into a linked role mention. | ||
* | ||
* @typeParam RoleId - This is inferred by the supplied role id | ||
* @param roleId - The role id to format | ||
*/ | ||
declare function linkedRoleMention<RoleId extends Snowflake>(roleId: RoleId): `<id:linked-roles:${RoleId}>`; | ||
/** | ||
* Formats an application command name, subcommand group name, subcommand name, and id into an application command mention. | ||
* | ||
* @typeParam N - This is inferred by the supplied command name | ||
* @typeParam G - This is inferred by the supplied subcommand group name | ||
* @typeParam S - This is inferred by the supplied subcommand name | ||
* @typeParam I - This is inferred by the supplied command id | ||
* @typeParam CommandName - This is inferred by the supplied command name | ||
* @typeParam SubcommandGroupName - This is inferred by the supplied subcommand group name | ||
* @typeParam SubcommandName - This is inferred by the supplied subcommand name | ||
* @typeParam CommandId - This is inferred by the supplied command id | ||
* @param commandName - The application command name to format | ||
@@ -337,9 +352,9 @@ * @param subcommandGroupName - The subcommand group name to format | ||
*/ | ||
declare function chatInputApplicationCommandMention<N extends string, G extends string, S extends string, I extends Snowflake>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`; | ||
declare function chatInputApplicationCommandMention<CommandName extends string, SubcommandGroupName extends string, SubcommandName extends string, CommandId extends Snowflake>(commandName: CommandName, subcommandGroupName: SubcommandGroupName, subcommandName: SubcommandName, commandId: CommandId): `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`; | ||
/** | ||
* Formats an application command name, subcommand name, and id into an application command mention. | ||
* | ||
* @typeParam N - This is inferred by the supplied command name | ||
* @typeParam S - This is inferred by the supplied subcommand name | ||
* @typeParam I - This is inferred by the supplied command id | ||
* @typeParam CommandName - This is inferred by the supplied command name | ||
* @typeParam SubcommandName - This is inferred by the supplied subcommand name | ||
* @typeParam CommandId - This is inferred by the supplied command id | ||
* @param commandName - The application command name to format | ||
@@ -349,66 +364,114 @@ * @param subcommandName - The subcommand name to format | ||
*/ | ||
declare function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(commandName: N, subcommandName: S, commandId: I): `</${N} ${S}:${I}>`; | ||
declare function chatInputApplicationCommandMention<CommandName extends string, SubcommandName extends string, CommandId extends Snowflake>(commandName: CommandName, subcommandName: SubcommandName, commandId: CommandId): `</${CommandName} ${SubcommandName}:${CommandId}>`; | ||
/** | ||
* Formats an application command name and id into an application command mention. | ||
* | ||
* @typeParam N - This is inferred by the supplied command name | ||
* @typeParam I - This is inferred by the supplied command id | ||
* @typeParam CommandName - This is inferred by the supplied command name | ||
* @typeParam CommandId - This is inferred by the supplied command id | ||
* @param commandName - The application command name to format | ||
* @param commandId - The application command id to format | ||
*/ | ||
declare function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(commandName: N, commandId: I): `</${N}:${I}>`; | ||
declare function chatInputApplicationCommandMention<CommandName extends string, CommandId extends Snowflake>(commandName: CommandName, commandId: CommandId): `</${CommandName}:${CommandId}>`; | ||
/** | ||
* Formats a non-animated emoji id into a fully qualified emoji identifier. | ||
* | ||
* @typeParam C - This is inferred by the supplied emoji id | ||
* @typeParam EmojiId - This is inferred by the supplied emoji id | ||
* @param emojiId - The emoji id to format | ||
*/ | ||
declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`; | ||
declare function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: false): `<:emoji:${EmojiId}>`; | ||
/** | ||
* Formats an animated emoji id into a fully qualified emoji identifier. | ||
* | ||
* @typeParam C - This is inferred by the supplied emoji id | ||
* @typeParam EmojiId - This is inferred by the supplied emoji id | ||
* @param emojiId - The emoji id to format | ||
* @param animated - Whether the emoji is animated | ||
*/ | ||
declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`; | ||
declare function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: true): `<a:emoji:${EmojiId}>`; | ||
/** | ||
* Formats an emoji id into a fully qualified emoji identifier. | ||
* | ||
* @typeParam C - This is inferred by the supplied emoji id | ||
* @typeParam EmojiId - This is inferred by the supplied emoji id | ||
* @param emojiId - The emoji id to format | ||
* @param animated - Whether the emoji is animated | ||
*/ | ||
declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`; | ||
declare function formatEmoji<EmojiId extends Snowflake>(emojiId: EmojiId, animated?: boolean): `<:emoji:${EmojiId}>` | `<a:emoji:${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 | ||
*/ | ||
declare 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 | ||
*/ | ||
declare 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 | ||
*/ | ||
declare function formatEmoji<EmojiId extends Snowflake, EmojiName extends string>(options: FormatEmojiOptions<EmojiId, EmojiName>): `<:${EmojiName}:${EmojiId}>` | `<a:${EmojiName}:${EmojiId}>`; | ||
/** | ||
* 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 | ||
*/ | ||
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 C - This is inferred by the supplied channel id | ||
* @typeParam ChannelId - This is inferred by the supplied channel id | ||
* @param channelId - The channel's id | ||
*/ | ||
declare function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`; | ||
declare function channelLink<ChannelId extends Snowflake>(channelId: ChannelId): `https://discord.com/channels/@me/${ChannelId}`; | ||
/** | ||
* Formats a channel link for a guild channel. | ||
* | ||
* @typeParam C - This is inferred by the supplied channel id | ||
* @typeParam G - This is inferred by the supplied guild id | ||
* @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 | ||
*/ | ||
declare function channelLink<C extends Snowflake, G extends Snowflake>(channelId: C, guildId: G): `https://discord.com/channels/${G}/${C}`; | ||
declare function channelLink<ChannelId extends Snowflake, GuildId extends Snowflake>(channelId: ChannelId, guildId: GuildId): `https://discord.com/channels/${GuildId}/${ChannelId}`; | ||
/** | ||
* Formats a message link for a direct message channel. | ||
* | ||
* @typeParam C - This is inferred by the supplied channel id | ||
* @typeParam M - This is inferred by the supplied message id | ||
* @typeParam ChannelId - This is inferred by the supplied channel id | ||
* @typeParam MessageId - This is inferred by the supplied message id | ||
* @param channelId - The channel's id | ||
* @param messageId - The message's id | ||
*/ | ||
declare function messageLink<C extends Snowflake, M extends Snowflake>(channelId: C, messageId: M): `https://discord.com/channels/@me/${C}/${M}`; | ||
declare function messageLink<ChannelId extends Snowflake, MessageId extends Snowflake>(channelId: ChannelId, messageId: MessageId): `https://discord.com/channels/@me/${ChannelId}/${MessageId}`; | ||
/** | ||
* Formats a message link for a guild channel. | ||
* | ||
* @typeParam C - This is inferred by the supplied channel id | ||
* @typeParam M - This is inferred by the supplied message id | ||
* @typeParam G - This is inferred by the supplied guild id | ||
* @typeParam ChannelId - This is inferred by the supplied channel id | ||
* @typeParam MessageId - This is inferred by the supplied message id | ||
* @typeParam GuildId - This is inferred by the supplied guild id | ||
* @param channelId - The channel's id | ||
@@ -418,4 +481,69 @@ * @param messageId - The message's id | ||
*/ | ||
declare function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(channelId: C, messageId: M, guildId: G): `https://discord.com/channels/${G}/${C}/${M}`; | ||
declare function messageLink<ChannelId extends Snowflake, MessageId extends Snowflake, GuildId extends Snowflake>(channelId: ChannelId, messageId: MessageId, guildId: GuildId): `https://discord.com/channels/${GuildId}/${ChannelId}/${MessageId}`; | ||
/** | ||
* The heading levels for expanded markdown. | ||
*/ | ||
declare enum HeadingLevel { | ||
/** | ||
* The first heading level. | ||
*/ | ||
One = 1, | ||
/** | ||
* The second heading level. | ||
*/ | ||
Two = 2, | ||
/** | ||
* The third heading level. | ||
*/ | ||
Three = 3 | ||
} | ||
/** | ||
* Formats the content into a heading level. | ||
* | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
* @param level - The heading level | ||
*/ | ||
declare function heading<Content extends string>(content: Content, level?: HeadingLevel.One): `# ${Content}`; | ||
/** | ||
* Formats the content into a heading level. | ||
* | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
* @param level - The heading level | ||
*/ | ||
declare function heading<Content extends string>(content: Content, level: HeadingLevel.Two): `## ${Content}`; | ||
/** | ||
* Formats the content into a heading level. | ||
* | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
* @param level - The heading level | ||
*/ | ||
declare function heading<Content extends string>(content: Content, level: HeadingLevel.Three): `### ${Content}`; | ||
/** | ||
* A type that recursively traverses into arrays. | ||
*/ | ||
type RecursiveArray<ItemType> = readonly (ItemType | RecursiveArray<ItemType>)[]; | ||
/** | ||
* Formats the elements in the array to an ordered list. | ||
* | ||
* @param list - The array of elements to list | ||
* @param startNumber - The starting number for the list | ||
*/ | ||
declare function orderedList(list: RecursiveArray<string>, startNumber?: number): string; | ||
/** | ||
* Formats the elements in the array to an unordered list. | ||
* | ||
* @param list - The array of elements to list | ||
*/ | ||
declare function unorderedList(list: RecursiveArray<string>): string; | ||
/** | ||
* Formats the content into a subtext. | ||
* | ||
* @typeParam Content - This is inferred by the supplied content | ||
* @param content - The content to wrap | ||
*/ | ||
declare function subtext<Content extends string>(content: Content): `-# ${Content}`; | ||
/** | ||
* Formats a date into a short date-time string. | ||
@@ -429,24 +557,40 @@ * | ||
* | ||
* @typeParam S - This is inferred by the supplied {@link TimestampStylesString} | ||
* @typeParam Style - This is inferred by the supplied {@link TimestampStylesString} | ||
* @param date - The date to format | ||
* @param style - The style to use | ||
*/ | ||
declare function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`; | ||
declare function time<Style extends TimestampStylesString>(date: Date, style: Style): `<t:${bigint}:${Style}>`; | ||
/** | ||
* Formats the given timestamp into a short date-time string. | ||
* | ||
* @typeParam C - This is inferred by the supplied timestamp | ||
* @typeParam Seconds - This is inferred by the supplied timestamp | ||
* @param seconds - A Unix timestamp in seconds | ||
*/ | ||
declare function time<C extends number>(seconds: C): `<t:${C}>`; | ||
declare function time<Seconds extends number>(seconds: Seconds): `<t:${Seconds}>`; | ||
/** | ||
* Formats the given timestamp into a short date-time string. | ||
* | ||
* @typeParam C - This is inferred by the supplied timestamp | ||
* @typeParam S - This is inferred by the supplied {@link TimestampStylesString} | ||
* @typeParam Seconds - This is inferred by the supplied timestamp | ||
* @typeParam Style - This is inferred by the supplied {@link TimestampStylesString} | ||
* @param seconds - A Unix timestamp in seconds | ||
* @param style - The style to use | ||
*/ | ||
declare function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`; | ||
declare function time<Seconds extends number, Style extends TimestampStylesString>(seconds: Seconds, style: Style): `<t:${Seconds}:${Style}>`; | ||
/** | ||
* Formats an application directory link. | ||
* | ||
* @typeParam ApplicationId - This is inferred by the supplied application id | ||
* @param applicationId - The application id | ||
*/ | ||
declare function applicationDirectory<ApplicationId extends Snowflake>(applicationId: ApplicationId): `https://discord.com/application-directory/${ApplicationId}/store`; | ||
/** | ||
* Formats an application directory SKU link. | ||
* | ||
* @typeParam ApplicationId - This is inferred by the supplied application id | ||
* @typeParam SKUId - This is inferred by the supplied SKU id | ||
* @param applicationId - The application id | ||
* @param skuId - The SKU id | ||
*/ | ||
declare function applicationDirectory<ApplicationId extends Snowflake, SKUId extends Snowflake>(applicationId: ApplicationId, skuId: SKUId): `https://discord.com/application-directory/${ApplicationId}/store/${SKUId}`; | ||
/** | ||
* The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles} | ||
@@ -510,3 +654,3 @@ * supported by Discord. | ||
*/ | ||
Shrug = "\u00AF_(\u30C4)_/\u00AF", | ||
Shrug = "\u00AF\\_(\u30C4)_/\u00AF", | ||
/** | ||
@@ -521,3 +665,32 @@ * `(╯°□°)╯︵ ┻━┻` | ||
} | ||
/** | ||
* All the available guild navigation mentions. | ||
*/ | ||
declare enum GuildNavigationMentions { | ||
/** | ||
* Browse Channels tab. | ||
*/ | ||
Browse = "<id:browse>", | ||
/** | ||
* Customize tab with the server's {@link https://discord.com/developers/docs/resources/guild#guild-onboarding-object | onboarding prompts}. | ||
*/ | ||
Customize = "<id:customize>", | ||
/** | ||
* {@link https://support.discord.com/hc/articles/13497665141655 | Server Guide} tab. | ||
*/ | ||
Guide = "<id:guide>", | ||
/** | ||
* {@link https://support.discord.com/hc/articles/10388356626711 | Linked Roles} tab. | ||
*/ | ||
LinkedRoles = "<id:linked-roles>" | ||
} | ||
export { EscapeMarkdownOptions, Faces, TimestampStyles, TimestampStylesString, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, escapeBold, escapeBulletedList, escapeCodeBlock, escapeEscape, escapeHeading, escapeInlineCode, escapeItalic, escapeMarkdown, escapeMaskedLink, escapeNumberedList, escapeSpoiler, escapeStrikethrough, escapeUnderline, formatEmoji, hideLinkEmbed, hyperlink, inlineCode, italic, messageLink, quote, roleMention, spoiler, strikethrough, time, underscore, userMention }; | ||
/** | ||
* The {@link https://github.com/discordjs/discord.js/blob/main/packages/formatters#readme | @discordjs/formatters} version | ||
* that you are currently using. | ||
* | ||
* @privateRemarks This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild. | ||
*/ | ||
declare const version: string; | ||
export { type EscapeMarkdownOptions, Faces, type FormatEmojiOptions, GuildNavigationMentions, HeadingLevel, type RecursiveArray, TimestampStyles, type TimestampStylesString, applicationDirectory, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, escapeBold, escapeBulletedList, escapeCodeBlock, escapeEscape, escapeHeading, escapeInlineCode, escapeItalic, escapeMarkdown, escapeMaskedLink, escapeNumberedList, escapeSpoiler, escapeStrikethrough, escapeUnderline, formatEmoji, heading, hideLinkEmbed, hyperlink, inlineCode, italic, linkedRoleMention, messageLink, orderedList, quote, roleMention, spoiler, strikethrough, subtext, time, underline, underscore, unorderedList, userMention, version }; |
@@ -25,3 +25,6 @@ "use strict"; | ||
Faces: () => Faces, | ||
GuildNavigationMentions: () => GuildNavigationMentions, | ||
HeadingLevel: () => HeadingLevel, | ||
TimestampStyles: () => TimestampStyles, | ||
applicationDirectory: () => applicationDirectory, | ||
blockQuote: () => blockQuote, | ||
@@ -47,2 +50,3 @@ bold: () => bold, | ||
formatEmoji: () => formatEmoji, | ||
heading: () => heading, | ||
hideLinkEmbed: () => hideLinkEmbed, | ||
@@ -52,3 +56,5 @@ hyperlink: () => hyperlink, | ||
italic: () => italic, | ||
linkedRoleMention: () => linkedRoleMention, | ||
messageLink: () => messageLink, | ||
orderedList: () => orderedList, | ||
quote: () => quote, | ||
@@ -58,5 +64,9 @@ roleMention: () => roleMention, | ||
strikethrough: () => strikethrough, | ||
subtext: () => subtext, | ||
time: () => time, | ||
underline: () => underline, | ||
underscore: () => underscore, | ||
userMention: () => userMention | ||
unorderedList: () => unorderedList, | ||
userMention: () => userMention, | ||
version: () => version | ||
}); | ||
@@ -72,3 +82,3 @@ module.exports = __toCommonJS(src_exports); | ||
italic: italic2 = true, | ||
underline = true, | ||
underline: underline2 = true, | ||
strikethrough: strikethrough2 = true, | ||
@@ -79,3 +89,3 @@ spoiler: spoiler2 = true, | ||
escape = true, | ||
heading = false, | ||
heading: heading2 = false, | ||
bulletedList = false, | ||
@@ -87,4 +97,3 @@ numberedList = false, | ||
return text.split("```").map((subString, index, array) => { | ||
if (index % 2 && index !== array.length - 1) | ||
return subString; | ||
if (index % 2 && index !== array.length - 1) return subString; | ||
return escapeMarkdown(subString, { | ||
@@ -94,3 +103,3 @@ inlineCode: inlineCode2, | ||
italic: italic2, | ||
underline, | ||
underline: underline2, | ||
strikethrough: strikethrough2, | ||
@@ -100,3 +109,3 @@ spoiler: spoiler2, | ||
escape, | ||
heading, | ||
heading: heading2, | ||
bulletedList, | ||
@@ -110,4 +119,3 @@ numberedList, | ||
return text.split(/(?<=^|[^`])`(?=[^`]|$)/g).map((subString, index, array) => { | ||
if (index % 2 && index !== array.length - 1) | ||
return subString; | ||
if (index % 2 && index !== array.length - 1) return subString; | ||
return escapeMarkdown(subString, { | ||
@@ -117,7 +125,7 @@ codeBlock: codeBlock2, | ||
italic: italic2, | ||
underline, | ||
underline: underline2, | ||
strikethrough: strikethrough2, | ||
spoiler: spoiler2, | ||
escape, | ||
heading, | ||
heading: heading2, | ||
bulletedList, | ||
@@ -130,26 +138,14 @@ numberedList, | ||
let res = text; | ||
if (escape) | ||
res = escapeEscape(res); | ||
if (inlineCode2) | ||
res = escapeInlineCode(res); | ||
if (codeBlock2) | ||
res = escapeCodeBlock(res); | ||
if (italic2) | ||
res = escapeItalic(res); | ||
if (bold2) | ||
res = escapeBold(res); | ||
if (underline) | ||
res = escapeUnderline(res); | ||
if (strikethrough2) | ||
res = escapeStrikethrough(res); | ||
if (spoiler2) | ||
res = escapeSpoiler(res); | ||
if (heading) | ||
res = escapeHeading(res); | ||
if (bulletedList) | ||
res = escapeBulletedList(res); | ||
if (numberedList) | ||
res = escapeNumberedList(res); | ||
if (maskedLink) | ||
res = escapeMaskedLink(res); | ||
if (escape) res = escapeEscape(res); | ||
if (inlineCode2) res = escapeInlineCode(res); | ||
if (codeBlock2) res = escapeCodeBlock(res); | ||
if (italic2) res = escapeItalic(res); | ||
if (bold2) res = escapeBold(res); | ||
if (underline2) res = escapeUnderline(res); | ||
if (strikethrough2) res = escapeStrikethrough(res); | ||
if (spoiler2) res = escapeSpoiler(res); | ||
if (heading2) res = escapeHeading(res); | ||
if (bulletedList) res = escapeBulletedList(res); | ||
if (numberedList) res = escapeNumberedList(res); | ||
if (maskedLink) res = escapeMaskedLink(res); | ||
return res; | ||
@@ -169,10 +165,8 @@ } | ||
const newText = text.replaceAll(/(?<=^|[^*])\*([^*]|\*\*|$)/g, (_, match) => { | ||
if (match === "**") | ||
return ++idx % 2 ? `\\*${match}` : `${match}\\*`; | ||
if (match === "**") return ++idx % 2 ? `\\*${match}` : `${match}\\*`; | ||
return `\\*${match}`; | ||
}); | ||
idx = 0; | ||
return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => { | ||
if (match === "__") | ||
return ++idx % 2 ? `\\_${match}` : `${match}\\_`; | ||
return newText.replaceAll(/(?<=^|[^_])(?<!<a?:.+|https?:\/\/\S+)_(?!:\d+>)([^_]|__|$)/g, (_, match) => { | ||
if (match === "__") return ++idx % 2 ? `\\_${match}` : `${match}\\_`; | ||
return `\\_${match}`; | ||
@@ -185,4 +179,3 @@ }); | ||
return text.replaceAll(/\*\*(\*)?/g, (_, match) => { | ||
if (match) | ||
return ++idx % 2 ? `${match}\\*\\*` : `\\*\\*${match}`; | ||
if (match) return ++idx % 2 ? `${match}\\*\\*` : `\\*\\*${match}`; | ||
return "\\*\\*"; | ||
@@ -194,5 +187,4 @@ }); | ||
let idx = 0; | ||
return text.replaceAll(/(?<!<a?:.+)__(_)?(?!:\d+>)/g, (_, match) => { | ||
if (match) | ||
return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`; | ||
return text.replaceAll(/(?<!<a?:.+|https?:\/\/\S+)__(_)?(?!:\d+>)/g, (_, match) => { | ||
if (match) return ++idx % 2 ? `${match}\\_\\_` : `\\_\\_${match}`; | ||
return "\\_\\_"; | ||
@@ -253,5 +245,9 @@ }); | ||
function underscore(content) { | ||
return underline(content); | ||
} | ||
__name(underscore, "underscore"); | ||
function underline(content) { | ||
return `__${content}__`; | ||
} | ||
__name(underscore, "underscore"); | ||
__name(underline, "underline"); | ||
function strikethrough(content) { | ||
@@ -293,2 +289,6 @@ return `~~${content}~~`; | ||
__name(roleMention, "roleMention"); | ||
function linkedRoleMention(roleId) { | ||
return `<id:linked-roles:${roleId}>`; | ||
} | ||
__name(linkedRoleMention, "linkedRoleMention"); | ||
function chatInputApplicationCommandMention(commandName, subcommandGroupName, subcommandName, commandId) { | ||
@@ -304,4 +304,9 @@ if (commandId !== void 0) { | ||
__name(chatInputApplicationCommandMention, "chatInputApplicationCommandMention"); | ||
function formatEmoji(emojiId, animated = false) { | ||
return `<${animated ? "a" : ""}:_:${emojiId}>`; | ||
function formatEmoji(emojiIdOrOptions, animated) { | ||
const options = typeof emojiIdOrOptions === "string" ? { | ||
id: emojiIdOrOptions, | ||
animated: animated ?? false | ||
} : emojiIdOrOptions; | ||
const { id, animated: isAnimated, name: emojiName } = options; | ||
return `<${isAnimated ? "a" : ""}:${emojiName ?? "emoji"}:${id}>`; | ||
} | ||
@@ -317,2 +322,38 @@ __name(formatEmoji, "formatEmoji"); | ||
__name(messageLink, "messageLink"); | ||
var HeadingLevel = /* @__PURE__ */ ((HeadingLevel2) => { | ||
HeadingLevel2[HeadingLevel2["One"] = 1] = "One"; | ||
HeadingLevel2[HeadingLevel2["Two"] = 2] = "Two"; | ||
HeadingLevel2[HeadingLevel2["Three"] = 3] = "Three"; | ||
return HeadingLevel2; | ||
})(HeadingLevel || {}); | ||
function heading(content, level) { | ||
switch (level) { | ||
case 3 /* Three */: | ||
return `### ${content}`; | ||
case 2 /* Two */: | ||
return `## ${content}`; | ||
default: | ||
return `# ${content}`; | ||
} | ||
} | ||
__name(heading, "heading"); | ||
function listCallback(element, startNumber, depth = 0) { | ||
if (Array.isArray(element)) { | ||
return element.map((element2) => listCallback(element2, startNumber, depth + 1)).join("\n"); | ||
} | ||
return `${" ".repeat(depth - 1)}${startNumber ? `${startNumber}.` : "-"} ${element}`; | ||
} | ||
__name(listCallback, "listCallback"); | ||
function orderedList(list, startNumber = 1) { | ||
return listCallback(list, Math.max(startNumber, 1)); | ||
} | ||
__name(orderedList, "orderedList"); | ||
function unorderedList(list) { | ||
return listCallback(list); | ||
} | ||
__name(unorderedList, "unorderedList"); | ||
function subtext(content) { | ||
return `-# ${content}`; | ||
} | ||
__name(subtext, "subtext"); | ||
function time(timeOrSeconds, style) { | ||
@@ -325,2 +366,7 @@ if (typeof timeOrSeconds !== "number") { | ||
__name(time, "time"); | ||
function applicationDirectory(applicationId, skuId) { | ||
const url = `https://discord.com/application-directory/${applicationId}/store`; | ||
return skuId ? `${url}/${skuId}` : url; | ||
} | ||
__name(applicationDirectory, "applicationDirectory"); | ||
var TimestampStyles = { | ||
@@ -371,3 +417,3 @@ /** | ||
var Faces = /* @__PURE__ */ ((Faces2) => { | ||
Faces2["Shrug"] = "\xAF_(\u30C4)_/\xAF"; | ||
Faces2["Shrug"] = "\xAF\\_(\u30C4)_/\xAF"; | ||
Faces2["Tableflip"] = "(\u256F\xB0\u25A1\xB0)\u256F\uFE35 \u253B\u2501\u253B"; | ||
@@ -377,6 +423,19 @@ Faces2["Unflip"] = "\u252C\u2500\u252C\u30CE( \xBA _ \xBA\u30CE)"; | ||
})(Faces || {}); | ||
var GuildNavigationMentions = /* @__PURE__ */ ((GuildNavigationMentions2) => { | ||
GuildNavigationMentions2["Browse"] = "<id:browse>"; | ||
GuildNavigationMentions2["Customize"] = "<id:customize>"; | ||
GuildNavigationMentions2["Guide"] = "<id:guide>"; | ||
GuildNavigationMentions2["LinkedRoles"] = "<id:linked-roles>"; | ||
return GuildNavigationMentions2; | ||
})(GuildNavigationMentions || {}); | ||
// src/index.ts | ||
var version = "1.0.0-dev.1732752782-e89c6b66a"; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Faces, | ||
GuildNavigationMentions, | ||
HeadingLevel, | ||
TimestampStyles, | ||
applicationDirectory, | ||
blockQuote, | ||
@@ -402,2 +461,3 @@ bold, | ||
formatEmoji, | ||
heading, | ||
hideLinkEmbed, | ||
@@ -407,3 +467,5 @@ hyperlink, | ||
italic, | ||
linkedRoleMention, | ||
messageLink, | ||
orderedList, | ||
quote, | ||
@@ -413,6 +475,10 @@ roleMention, | ||
strikethrough, | ||
subtext, | ||
time, | ||
underline, | ||
underscore, | ||
userMention | ||
unorderedList, | ||
userMention, | ||
version | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"$schema": "https://json.schemastore.org/package.json", | ||
"name": "@discordjs/formatters", | ||
"version": "1.0.0-dev.1690416583-8f4256d.0", | ||
"version": "1.0.0-dev.1732752782-e89c6b66a", | ||
"description": "A set of functions to format strings for Discord.", | ||
"scripts": { | ||
"test": "vitest run", | ||
"build": "tsup", | ||
"build:docs": "tsc -p tsconfig.docs.json", | ||
"lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty", | ||
"format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty", | ||
"docs": "yarn build:docs && api-extractor run --local && api-extractor run --local --config ./api-extractor-docs.json", | ||
"prepack": "yarn build && yarn lint", | ||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'", | ||
"release": "cliff-jumper" | ||
"exports": { | ||
".": { | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
} | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"typings": "./dist/index.d.ts", | ||
"exports": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"directories": { | ||
@@ -34,3 +31,3 @@ "lib": "src", | ||
"SpaceEEC <spaceeec@yahoo.com>", | ||
"Vlad Frangu <kingdgrizzle@gmail.com>", | ||
"Vlad Frangu <me@vladfrangu.dev>", | ||
"Aura Román <kyradiscord@gmail.com>" | ||
@@ -49,26 +46,40 @@ ], | ||
"homepage": "https://discord.js.org", | ||
"funding": "https://github.com/discordjs/discord.js?sponsor", | ||
"dependencies": { | ||
"discord-api-types": "^0.37.49" | ||
"discord-api-types": "^0.37.109" | ||
}, | ||
"devDependencies": { | ||
"@favware/cliff-jumper": "^2.1.1", | ||
"@microsoft/api-extractor": "^7.36.3", | ||
"@types/node": "16.18.38", | ||
"@vitest/coverage-c8": "^0.33.0", | ||
"@favware/cliff-jumper": "^4.1.0", | ||
"@types/node": "^20.17.8", | ||
"@vitest/coverage-v8": "^2.1.5", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.45.0", | ||
"eslint-config-neon": "^0.1.47", | ||
"eslint-formatter-pretty": "^5.0.0", | ||
"prettier": "^2.8.8", | ||
"tsup": "^7.1.0", | ||
"turbo": "^1.10.8", | ||
"typescript": "^5.1.6", | ||
"vitest": "^0.33.0" | ||
"esbuild-plugin-version-injector": "^1.2.1", | ||
"eslint": "^8.57.1", | ||
"eslint-config-neon": "^0.1.62", | ||
"eslint-formatter-pretty": "^6.0.1", | ||
"prettier": "^3.3.3", | ||
"tsup": "^8.3.5", | ||
"turbo": "^2.3.0", | ||
"typescript": "~5.5.4", | ||
"vitest": "^2.1.5", | ||
"@discordjs/api-extractor": "^7.38.1", | ||
"@discordjs/scripts": "^0.1.0" | ||
}, | ||
"engines": { | ||
"node": ">=16.9.0" | ||
"node": ">=20" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
"access": "public", | ||
"provenance": true | ||
}, | ||
"scripts": { | ||
"test": "vitest run", | ||
"build": "tsc --noEmit && tsup", | ||
"build:docs": "tsc -p tsconfig.docs.json", | ||
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src __tests__", | ||
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src __tests__", | ||
"docs": "pnpm run build:docs && api-extractor run --local --minify && generate-split-documentation", | ||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'", | ||
"release": "cliff-jumper" | ||
} | ||
} |
@@ -26,3 +26,3 @@ <div align="center"> | ||
**Node.js 16.9.0 or newer is required.** | ||
**Node.js 20 or newer is required.** | ||
@@ -33,2 +33,3 @@ ```sh | ||
pnpm add @discordjs/formatters | ||
bun add @discordjs/formatters | ||
``` | ||
@@ -35,0 +36,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
172577
1524
83
15
9
Updateddiscord-api-types@^0.37.109