feat: move internal regular expressions to static properties (#5384)

This commit is contained in:
Jan
2021-04-15 00:36:35 +02:00
committed by GitHub
parent 900e57657e
commit 207735cedc
4 changed files with 19 additions and 4 deletions

View File

@@ -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);
}
/**