From f6f804bd14b209a45e441fbc24bd7882c9678baf Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 10 Sep 2017 15:27:52 +0200 Subject: [PATCH] Remove String#format in favor of template strings --- jssrc/utils.js | 36 ------------------------------------ jssrc/wifi.js | 7 ++++--- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/jssrc/utils.js b/jssrc/utils.js index aa09f9e..9b53a5b 100755 --- a/jssrc/utils.js +++ b/jssrc/utils.js @@ -72,42 +72,6 @@ Math.log10 = Math.log10 || function (x) { return Math.log(x) / Math.LN10 } -/** - * Perform a substitution in the given string. - * - * Arguments - array or list of replacements. - * Arguments numeric keys will replace {0}, {1} etc. - * Named keys also work, ie. {foo: "bar"} -> replaces {foo} with bar. - * - * Braces are added to keys if missing. - * - * @returns {String} result - */ -String.prototype.format = function () { - let out = this - let repl = arguments - - if (arguments.length == 1 && (Array.isArray(arguments[0]) || typeof arguments[0] == 'object')) { - repl = arguments[0] - } - - for (let ph in repl) { - if (repl.hasOwnProperty(ph)) { - const ph_orig = ph - - if (!ph.match(/^\{.*\}$/)) { - ph = '{' + ph + '}' - } - - // replace all occurrences - const pattern = new RegExp(rgxe(ph), 'g') - out = out.replace(pattern, repl[ph_orig]) - } - } - - return out -} - /** HTML escape */ function e (str) { return $.htmlEscape(str) diff --git a/jssrc/wifi.js b/jssrc/wifi.js index cab085b..3669241 100644 --- a/jssrc/wifi.js +++ b/jssrc/wifi.js @@ -82,10 +82,11 @@ } let inner = mk('div') + let escapedSSID = $.htmlEscape(ap.essid) $(inner).addClass('inner') - .htmlAppend('
{0}
'.format(ap.rssi_perc)) - .htmlAppend('
{0}
'.format($.htmlEscape(ap.essid))) - .htmlAppend('
{0}
'.format(authStr[ap.enc])) + .htmlAppend(`
${ap.rssi_perc}
`) + .htmlAppend(`
${escapedSSID}
`) + .htmlAppend(`
${authStr[ap.enc]}
`) $item.on('click', function () { let $th = $(this)