From 2938c4338dffd2b9cc0fe20070a89099c7a1e660 Mon Sep 17 00:00:00 2001 From: Tomas Chmelevskij Date: Thu, 12 Nov 2020 22:01:01 +0100 Subject: [PATCH] chore: remove custom string formatting String template literals are in built way to handle these cases now --- src/js/gui.js | 7 +---- src/js/injected_methods.js | 16 ----------- src/js/tabs/firmware_flasher.js | 50 +++++++++++++++++++++++---------- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/js/gui.js b/src/js/gui.js index 705a112d..0d1183f4 100644 --- a/src/js/gui.js +++ b/src/js/gui.js @@ -262,12 +262,7 @@ GuiControl.prototype.log = function (message) { const seconds = (d.getSeconds() < 10) ? `0${d.getSeconds()}` : d.getSeconds(); const time = `${hours}:${minutes}:${seconds}`; - const formattedDate = "{0}-{1}-{2} {3}".format( - year, - month, - date, - `@ ${time}` - ); + const formattedDate = `${year}-${month}-${date} @${time}`; $('div.wrapper', commandLog).append(`

${formattedDate} -- ${message}

`); commandLog.scrollTop($('div.wrapper', commandLog).height()); }; diff --git a/src/js/injected_methods.js b/src/js/injected_methods.js index ca708062..1e717b32 100644 --- a/src/js/injected_methods.js +++ b/src/js/injected_methods.js @@ -2,22 +2,6 @@ Number.prototype.clamp = function(min, max) { return Math.min(Math.max(this, min), max); }; -/** - * String formatting now supports currying (partial application). - * For a format string with N replacement indices, you can call .format - * with M <= N arguments. The result is going to be a format string - * with N-M replacement indices, properly counting from 0 .. N-M. - * The following Example should explain the usage of partial applied format: - * "{0}:{1}:{2}".format("a","b","c") === "{0}:{1}:{2}".format("a","b").format("c") - * "{0}:{1}:{2}".format("a").format("b").format("c") === "{0}:{1}:{2}".format("a").format("b", "c") - **/ -String.prototype.format = function () { - var args = arguments; - return this.replace(/\{(\d+)\}/g, function (t, i) { - return args[i] !== void 0 ? args[i] : "{"+(i-args.length)+"}"; - }); -}; - Array.prototype.push8 = function(val) { this.push(0xFF & val); return this; diff --git a/src/js/tabs/firmware_flasher.js b/src/js/tabs/firmware_flasher.js index 9da5c223..bb7dec58 100644 --- a/src/js/tabs/firmware_flasher.js +++ b/src/js/tabs/firmware_flasher.js @@ -150,10 +150,9 @@ TABS.firmware_flasher.initialize = function (callback) { descriptors.forEach(function(descriptor){ if($.inArray(target, selectTargets) == -1) { selectTargets.push(target); - var select_e = - $("".format( - descriptor.target - )); + var select_e = $( + ``, + ); boards_e.append(select_e); } }); @@ -352,8 +351,14 @@ TABS.firmware_flasher.initialize = function (callback) { var buildType_e = $('select[name="build_type"]'); function buildBuildTypeOptionsList() { buildType_e.empty(); - buildTypesToShow.forEach((build, index) => { - buildType_e.append($("".format(index, build.tag ? i18n.getMessage(build.tag) : build.title))) + buildTypesToShow.forEach(({ tag, title }, index) => { + buildType_e.append( + $( + `` + ) + ); }); buildType_e.val($('select[name="build_type"] option:first').val()); } @@ -455,7 +460,13 @@ TABS.firmware_flasher.initialize = function (callback) { versions_element.empty(); const targetVersions = Object.keys(builds); if (targetVersions.length > 0) { - versions_element.append($("".format(i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersionFor'), target))); + versions_element.append( + $( + `` + ) + ); targetVersions .sort(sortVersions) .forEach(function(versionName) { @@ -478,12 +489,9 @@ TABS.firmware_flasher.initialize = function (callback) { } - var select_e = - $("".format( - versionName, - version.descriptor.date, - versionLabel - )); + var select_e = $( + `` + ); if (FirmwareCache.has(version.descriptor)) { select_e.addClass("cached"); } @@ -564,11 +572,23 @@ TABS.firmware_flasher.initialize = function (callback) { clearBufferedFirmware(); versions_e.empty(); - versions_e.append($("".format(i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersion')))); + versions_e.append( + $( + `` + ) + ); } else { // Show a loading message as there is a delay in loading a configuration versions_e.empty(); - versions_e.append($("".format(i18n.getMessage('firmwareFlasherOptionLoading')))); + versions_e.append( + $( + `` + ) + ); let selecteBuild = buildTypesToShow[$('select[name="build_type"]').val()]; const builds = [];