@@ -658,6 +658,60 @@ export function applicationDirectory<ApplicationId extends Snowflake, SKUId exte
658658 return skuId ? `${ url } /${ skuId } ` : url ;
659659}
660660
661+ /**
662+ * Formats an email address into an email mention.
663+ *
664+ * @typeParam Email - This is inferred by the supplied email address
665+ * @param email - The email address to format
666+ */
667+ export function email < Email extends string > ( email : Email ) : `<${Email } >`;
668+
669+ /**
670+ * Formats an email address and headers into an email mention.
671+ *
672+ * @typeParam Email - This is inferred by the supplied email address
673+ * @param email - The email address to format
674+ * @param headers - Optional headers to include in the email mention
675+ */
676+ export function email < Email extends string > (
677+ email : Email ,
678+ headers : Record < string , string | readonly string [ ] > | undefined ,
679+ ) : `<${Email } ?${string } >`;
680+
681+ /**
682+ * Formats an email address into an email mention.
683+ *
684+ * @typeParam Email - This is inferred by the supplied email address
685+ * @param email - The email address to format
686+ * @param headers - Optional headers to include in the email mention
687+ */
688+ export function email < Email extends string > ( email : Email , headers ?: Record < string , string | readonly string [ ] > ) {
689+ if ( headers ) {
690+ // eslint-disable-next-line n/prefer-global/url-search-params
691+ const searchParams = new URLSearchParams (
692+ Object . fromEntries ( Object . entries ( headers ) . map ( ( [ key , value ] ) => [ key . toLowerCase ( ) , value ] ) ) ,
693+ ) ;
694+
695+ return `<${ email } ?${ searchParams . toString ( ) } >` as const ;
696+ }
697+
698+ return `<${ email } >` as const ;
699+ }
700+
701+ /**
702+ * Formats a phone number into a phone number mention.
703+ *
704+ * @typeParam PhoneNumber - This is inferred by the supplied phone number
705+ * @param phoneNumber - The phone number to format. Must start with a `+` sign.
706+ */
707+ export function phoneNumber < PhoneNumber extends `+${string } `> ( phoneNumber : PhoneNumber ) {
708+ if ( ! phoneNumber . startsWith ( '+' ) ) {
709+ throw new Error ( 'Phone number must start with a "+" sign.' ) ;
710+ }
711+
712+ return `<${ phoneNumber } >` as const ;
713+ }
714+
661715/**
662716 * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles}
663717 * supported by Discord.
0 commit comments