Skip to content

Commit

Permalink
feat: implement FormatPatterns (#79)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
  • Loading branch information
Fyko and vladfrangu committed Feb 2, 2021
1 parent 75ed123 commit 4e4a084
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 4e4a084

Please sign in to comment.