Remove String#format in favor of template strings

cpsdqs/unified-input
cpsdqs 7 years ago
parent f059a35277
commit f6f804bd14
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 36
      jssrc/utils.js
  2. 7
      jssrc/wifi.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)

@ -82,10 +82,11 @@
}
let inner = mk('div')
let escapedSSID = $.htmlEscape(ap.essid)
$(inner).addClass('inner')
.htmlAppend('<div class="rssi">{0}</div>'.format(ap.rssi_perc))
.htmlAppend('<div class="essid" title="{0}">{0}</div>'.format($.htmlEscape(ap.essid)))
.htmlAppend('<div class="auth">{0}</div>'.format(authStr[ap.enc]))
.htmlAppend(`<div class="rssi">${ap.rssi_perc}</div>`)
.htmlAppend(`<div class="essid" title="${escapedSSID}">${escapedSSID}</div>`)
.htmlAppend(`<div class="auth">${authStr[ap.enc]}</div>`)
$item.on('click', function () {
let $th = $(this)

Loading…
Cancel
Save