Sync with rauenzi/BetterDiscordApp 6fa2960

This commit is contained in:
Jean Ouina 2020-07-19 13:33:44 +02:00
parent b0ecc2a669
commit d854e057c4
4 changed files with 42 additions and 7 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -247,8 +247,7 @@ Core.prototype.checkForGuilds = function() {
};
Core.prototype.injectExternals = async function() {
await DOM.addScript("ace-script", "https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js");
if (window.require.original) window.require = window.require.original;
// No externals
};
Core.prototype.initSettings = function () {

View File

@ -71,6 +71,24 @@ export default class Utils {
}
}
/**
* Format strings with placeholders (`{{placeholder}}`) into full strings.
* Quick example: `PluginUtilities.formatString("Hello, {{user}}", {user: "Zerebos"})`
* would return "Hello, Zerebos".
* @param {string} string - string to format
* @param {object} values - object literal of placeholders to replacements
* @returns {string} the properly formatted string
*/
static formatString(string, values) {
for (const val in values) {
let replacement = values[val];
if (Array.isArray(replacement)) replacement = JSON.stringify(replacement);
if (typeof(replacement) === "object" && replacement !== null) replacement = replacement.toString();
string = string.replace(new RegExp(`{{${val}}}`, "g"), replacement);
}
return string;
}
static escape(s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
}