mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
feat: move internal regular expressions to static properties (#5384)
This commit is contained in:
@@ -5,6 +5,8 @@ const path = require('path');
|
||||
const stream = require('stream');
|
||||
const fetch = require('node-fetch');
|
||||
const { Error: DiscordError, TypeError } = require('../errors');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
|
||||
/**
|
||||
* The DataResolver identifies different objects and tries to resolve a specific piece of information from them.
|
||||
@@ -36,8 +38,7 @@ class DataResolver {
|
||||
* @returns {string}
|
||||
*/
|
||||
static resolveCode(data, regex) {
|
||||
const match = regex.exec(data);
|
||||
return match ? match[1] || data : data;
|
||||
return data.matchAll(regex).next().value?.[1] ?? data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,7 @@ class DataResolver {
|
||||
* @returns {string}
|
||||
*/
|
||||
static resolveInviteCode(data) {
|
||||
return this.resolveCode(data, /discord(?:(?:app)?\.com\/invite|\.gg(?:\/invite)?)\/([\w-]{2,255})/i);
|
||||
return this.resolveCode(data, Invite.INVITES_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ class DataResolver {
|
||||
* @returns {string}
|
||||
*/
|
||||
static resolveGuildTemplateCode(data) {
|
||||
return this.resolveCode(data, /discord(?:app)?\.(?:com\/template|new)\/([\w-]{2,255})/i);
|
||||
return this.resolveCode(data, GuildTemplate.GUILD_TEMPLATES_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user