Skip to content

Commit fbf1de8

Browse files
committed
feat(globals): de-duplicate timestamp formatting patterns
1 parent cdec113 commit fbf1de8

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

deno/globals.ts

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

globals.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ export type Snowflake = string;
88
*/
99
export type Permissions = string;
1010

11+
const timestampStyles = 'DFRSTdfst';
12+
const timestampLength = 13;
13+
1114
/**
1215
* @see {@link https://discord.com/developers/docs/reference#message-formatting-formats}
1316
*/
@@ -76,20 +79,19 @@ export const FormattingPatterns = {
7679
*
7780
* The `timestamp` and `style` group properties are present on the `exec` result of this expression
7881
*/
79-
// eslint-disable-next-line prefer-named-capture-group, unicorn/better-regex
80-
Timestamp: /<t:(?<timestamp>-?\d{1,13})(:(?<style>[DFRSTdfst]))?>/,
82+
Timestamp: new RegExp(`<t:(?<timestamp>-?\\d{1,${timestampLength}})(:(?<style>[${timestampStyles}]))?>`),
8183
/**
8284
* Regular expression for matching strictly default styled timestamps
8385
*
8486
* The `timestamp` group property is present on the `exec` result of this expression
8587
*/
86-
DefaultStyledTimestamp: /<t:(?<timestamp>-?\d{1,13})>/,
88+
DefaultStyledTimestamp: new RegExp(`<t:(?<timestamp>-?\\d{1,${timestampLength}})>`),
8789
/**
8890
* Regular expression for matching strictly custom styled timestamps
8991
*
9092
* The `timestamp` and `style` group properties are present on the `exec` result of this expression
9193
*/
92-
StyledTimestamp: /<t:(?<timestamp>-?\d{1,13}):(?<style>[DFRTdft])>/,
94+
StyledTimestamp: new RegExp(`<t:(?<timestamp>-?\\d{1,${timestampLength}}):(?<style>[${timestampStyles}])>`),
9395
/**
9496
* Regular expression for matching a guild navigation mention
9597
*

0 commit comments

Comments
 (0)