From b6be82b8edefa452e72ed53391971e53d9dccf83 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 25 Jul 2014 23:28:21 +0200 Subject: jsrrdgraph: Fixed jshint warnings/errors Many fall in the category missing semicolon, but there are legitimate bugs (like throwing an error with an undefined variable, using isInfinite instead of !isFinite or fabs instead of Math.abs). At some places, I moved the variable declarations to avoid duplicate definition warnings. Redundant breaks have been removed (after return / throw). Global variables were implicitly defined in RrdDataFile (which caught my attention) and Base64, these have been made local. Also fixed some whitespace errors. Yay, the consistency. Not all (style) issues are fixed. --- js/sprintf.js | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'js/sprintf.js') diff --git a/js/sprintf.js b/js/sprintf.js index 4d61fa2..244fe2a 100644 --- a/js/sprintf.js +++ b/js/sprintf.js @@ -19,60 +19,55 @@ "use strict"; function sprintf() -{ +{ var argc = 0; var args = arguments; var fmt = args[argc++]; - - function lpad (str, padString, length) - { - while (str.length < length) - str = padString + str; - return str; - }; + + function lpad (str, padString, length) + { + while (str.length < length) + str = padString + str; + return str; + } function format (match, width, dot, precision, length, conversion) { - if (match === '%%') return '%'; + if (match === '%%') return '%'; var value = args[argc++]; var prefix; - if (width === undefined) + if (width === undefined) width = 0; - else + else width = +width; - + if (precision === undefined) precision = conversion == 'd' ? 0 : 6; - else + else precision = +precision; switch (conversion) { case 's': case 'c': return value; - break; case 'd': return parseInt(value, 10); - break; case 'e': prefix = value < 0 ? '-' : ''; return lpad(prefix+Math.abs(value).toExponential(precision),' ',width); - break; case 'F': case 'f': prefix = value < 0 ? '-' : ''; return lpad(prefix+Math.abs(value).toFixed(precision),' ',width); - break; case 'g': prefix = value < 0 ? '-' : ''; return lpad(prefix+Math.abs(value).toPrecision(precision),' ',width); - break; default: return match; } - }; + } return fmt.replace(/%(\d+)?(\.(\d+))?(l?)([%scdfFeg])/g,format); -}; +} -- cgit v1.1