feat: implement FormatPatterns (#79)

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
Carter
2021-02-02 15:25:59 -07:00
committed by GitHub
parent 75ed123018
commit 4e4a084003

View File

@@ -164,3 +164,63 @@ export type Snowflake = `${bigint}`;
* @internal
*/
export type Permissions = `${bigint}`;
/**
* https://discord.com/developers/docs/reference#message-formatting-formats
*/
export const FormattingPatterns = {
/**
* Regular expression for matching a user mention, strictly without a nickname
*
* The `userID` group property is present on the `exec` result of this expression
*/
User: /<@(?<userID>\d{17,20})>/,
/**
* Regular expression for matching a user mention, strictly with a nickname
*
* The `userID` group property is present on the `exec` result of this expression
*/
UserWithNickname: /<@!(?<userID>\d{17,20})>/,
/**
* Regular expression for matching a user mention, with or without a nickname
*
* The `userID` group property is present on the `exec` result of this expression
*/
UserWithOptionalNickname: /<@!?(?<userID>\d{17,20})>/,
/**
* Regular expression for matching a channel mention
*
* The `channelID` group property is present on the `exec` result of this expression
*/
Channel: /<#(?<channelID>\d{17,20})>/,
/**
* Regular expression for matching a role mention
*
* The `roleID` group property is present on the `exec` result of this expression
*/
Role: /<@&(?<roleID>\d{17,20})>/,
/**
* Regular expression for matching a custom emoji, either static or animated
*
* The `emojiAnimated`, `emojiName` and `emojiID` group properties are present on the `exec` result of this expression
*/
Emoji: /<(?<emojiAnimated>a)?:(?<emojiName>\w{2,32}):(?<emojiID>\d{17,20})>/,
/**
* Regular expression for matching strictly an animated custom emoji
*
* The `emojiAnimated`, `emojiName` and `emojiID` group properties are present on the `exec` result of this expression
*/
AnimatedEmoji: /<(?<emojiAnimated>a):(?<emojiName>\w{2,32}):(?<emojiID>\d{17,20})>/,
/**
* Regular expression for matching strictly a static custom emoji
*
* The `emojiName` and `emojiID` group properties are present on the `exec` result of this expression
*/
StaticEmoji: /<:(?<emojiName>\w{2,32}):(?<emojiID>\d{17,20})>/,
} as const;
/**
* Freezes the formatting patterns
* @internal
*/
Object.freeze(FormattingPatterns);