chore: release v2.8.11

This commit is contained in:
March 7th
2022-11-04 19:46:05 +07:00
parent 83e764aad5
commit 04296bd6d1
6 changed files with 98 additions and 22 deletions

View File

@@ -115,17 +115,21 @@ class Util extends null {
/**
* Options used to escape markdown.
* @typedef {Object} EscapeMarkdownOptions
* @property {boolean} [codeBlock=true] Whether to escape code blocks or not
* @property {boolean} [inlineCode=true] Whether to escape inline code or not
* @property {boolean} [bold=true] Whether to escape bolds or not
* @property {boolean} [italic=true] Whether to escape italics or not
* @property {boolean} [underline=true] Whether to escape underlines or not
* @property {boolean} [strikethrough=true] Whether to escape strikethroughs or not
* @property {boolean} [spoiler=true] Whether to escape spoilers or not
* @property {boolean} [codeBlockContent=true] Whether to escape text inside code blocks or not
* @property {boolean} [inlineCodeContent=true] Whether to escape text inside inline code or not
* @property {boolean} [codeBlock=true] Whether to escape code blocks
* @property {boolean} [inlineCode=true] Whether to escape inline code
* @property {boolean} [bold=true] Whether to escape bolds
* @property {boolean} [italic=true] Whether to escape italics
* @property {boolean} [underline=true] Whether to escape underlines
* @property {boolean} [strikethrough=true] Whether to escape strikethroughs
* @property {boolean} [spoiler=true] Whether to escape spoilers
* @property {boolean} [codeBlockContent=true] Whether to escape text inside code blocks
* @property {boolean} [inlineCodeContent=true] Whether to escape text inside inline code
* @property {boolean} [escape=true] Whether to escape escape characters
* @property {boolean} [heading=false] Whether to escape headings
* @property {boolean} [bulletedList=false] Whether to escape bulleted lists
* @property {boolean} [numberedList=false] Whether to escape numbered lists
* @property {boolean} [maskedLink=false] Whether to escape masked links
*/
/**
* Escapes any Discord-flavour markdown in a string.
* @param {string} text Content to escape
@@ -144,6 +148,11 @@ class Util extends null {
spoiler = true,
codeBlockContent = true,
inlineCodeContent = true,
escape = true,
heading = false,
bulletedList = false,
numberedList = false,
maskedLink = false,
} = {},
) {
if (!codeBlockContent) {
@@ -159,6 +168,11 @@ class Util extends null {
strikethrough,
spoiler,
inlineCodeContent,
escape,
heading,
bulletedList,
numberedList,
maskedLink,
});
})
.join(codeBlock ? '\\`\\`\\`' : '```');
@@ -175,10 +189,16 @@ class Util extends null {
underline,
strikethrough,
spoiler,
escape,
heading,
bulletedList,
numberedList,
maskedLink,
});
})
.join(inlineCode ? '\\`' : '`');
}
if (escape) text = Util.escapeEscape(text);
if (inlineCode) text = Util.escapeInlineCode(text);
if (codeBlock) text = Util.escapeCodeBlock(text);
if (italic) text = Util.escapeItalic(text);
@@ -186,9 +206,12 @@ class Util extends null {
if (underline) text = Util.escapeUnderline(text);
if (strikethrough) text = Util.escapeStrikethrough(text);
if (spoiler) text = Util.escapeSpoiler(text);
if (heading) text = Util.escapeHeading(text);
if (bulletedList) text = Util.escapeBulletedList(text);
if (numberedList) text = Util.escapeNumberedList(text);
if (maskedLink) text = Util.escapeMaskedLink(text);
return text;
}
/**
* Escapes code block markdown in a string.
* @param {string} text Content to escape
@@ -197,16 +220,14 @@ class Util extends null {
static escapeCodeBlock(text) {
return text.replaceAll('```', '\\`\\`\\`');
}
/**
* Escapes inline code markdown in a string.
* @param {string} text Content to escape
* @returns {string}
*/
static escapeInlineCode(text) {
return text.replace(/(?<=^|[^`])`(?=[^`]|$)/g, '\\`');
return text.replace(/(?<=^|[^`])``?(?=[^`]|$)/g, match => (match.length === 2 ? '\\`\\`' : '\\`'));
}
/**
* Escapes italic markdown in a string.
* @param {string} text Content to escape
@@ -224,7 +245,6 @@ class Util extends null {
return `\\_${match}`;
});
}
/**
* Escapes bold markdown in a string.
* @param {string} text Content to escape
@@ -237,7 +257,6 @@ class Util extends null {
return '\\*\\*';
});
}
/**
* Escapes underline markdown in a string.
* @param {string} text Content to escape
@@ -250,7 +269,6 @@ class Util extends null {
return '\\_\\_';
});
}
/**
* Escapes strikethrough markdown in a string.
* @param {string} text Content to escape
@@ -259,7 +277,6 @@ class Util extends null {
static escapeStrikethrough(text) {
return text.replaceAll('~~', '\\~\\~');
}
/**
* Escapes spoiler markdown in a string.
* @param {string} text Content to escape
@@ -268,6 +285,46 @@ class Util extends null {
static escapeSpoiler(text) {
return text.replaceAll('||', '\\|\\|');
}
/**
* Escapes escape characters in a string.
* @param {string} text Content to escape
* @returns {string}
*/
static escapeEscape(text) {
return text.replaceAll('\\', '\\\\');
}
/**
* Escapes heading characters in a string.
* @param {string} text Content to escape
* @returns {string}
*/
static escapeHeading(text) {
return text.replaceAll(/^( {0,2}[*-] +)?(#{1,3} )/gm, '$1\\$2');
}
/**
* Escapes bulleted list characters in a string.
* @param {string} text Content to escape
* @returns {string}
*/
static escapeBulletedList(text) {
return text.replaceAll(/^( *)[*-]( +)/gm, '$1\\-$2');
}
/**
* Escapes numbered list characters in a string.
* @param {string} text Content to escape
* @returns {string}
*/
static escapeNumberedList(text) {
return text.replaceAll(/^( *\d+)\./gm, '$1\\.');
}
/**
* Escapes masked link characters in a string.
* @param {string} text Content to escape
* @returns {string}
*/
static escapeMaskedLink(text) {
return text.replaceAll(/\[.+\]\(.+\)/gm, '\\$&');
}
/**
* @typedef {Object} FetchRecommendedShardsOptions