diff options
author | Peter Wu | 2014-07-25 23:28:21 +0200 |
---|---|---|
committer | Pim van den Berg | 2014-08-02 12:29:32 +0200 |
commit | b6be82b8edefa452e72ed53391971e53d9dccf83 (patch) | |
tree | 01a33ac72f6ef7e6e5c607238bc5e4dd3a8751fe /js/sprintf.js | |
parent | support php versions without json support and show a warning message (diff) | |
download | apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.zip apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.tar.gz apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.tar.bz2 apt-panopticon_cgp-b6be82b8edefa452e72ed53391971e53d9dccf83.tar.xz |
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.
Diffstat (limited to 'js/sprintf.js')
-rw-r--r-- | js/sprintf.js | 35 |
1 files changed, 15 insertions, 20 deletions
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 @@ | |||
19 | "use strict"; | 19 | "use strict"; |
20 | 20 | ||
21 | function sprintf() | 21 | function sprintf() |
22 | { | 22 | { |
23 | var argc = 0; | 23 | var argc = 0; |
24 | var args = arguments; | 24 | var args = arguments; |
25 | var fmt = args[argc++]; | 25 | var fmt = args[argc++]; |
26 | 26 | ||
27 | function lpad (str, padString, length) | 27 | function lpad (str, padString, length) |
28 | { | 28 | { |
29 | while (str.length < length) | 29 | while (str.length < length) |
30 | str = padString + str; | 30 | str = padString + str; |
31 | return str; | 31 | return str; |
32 | }; | 32 | } |
33 | 33 | ||
34 | function format (match, width, dot, precision, length, conversion) | 34 | function format (match, width, dot, precision, length, conversion) |
35 | { | 35 | { |
36 | if (match === '%%') return '%'; | 36 | if (match === '%%') return '%'; |
37 | 37 | ||
38 | var value = args[argc++]; | 38 | var value = args[argc++]; |
39 | var prefix; | 39 | var prefix; |
40 | 40 | ||
41 | if (width === undefined) | 41 | if (width === undefined) |
42 | width = 0; | 42 | width = 0; |
43 | else | 43 | else |
44 | width = +width; | 44 | width = +width; |
45 | 45 | ||
46 | if (precision === undefined) | 46 | if (precision === undefined) |
47 | precision = conversion == 'd' ? 0 : 6; | 47 | precision = conversion == 'd' ? 0 : 6; |
48 | else | 48 | else |
49 | precision = +precision; | 49 | precision = +precision; |
50 | 50 | ||
51 | switch (conversion) { | 51 | switch (conversion) { |
52 | case 's': | 52 | case 's': |
53 | case 'c': | 53 | case 'c': |
54 | return value; | 54 | return value; |
55 | break; | ||
56 | case 'd': | 55 | case 'd': |
57 | return parseInt(value, 10); | 56 | return parseInt(value, 10); |
58 | break; | ||
59 | case 'e': | 57 | case 'e': |
60 | prefix = value < 0 ? '-' : ''; | 58 | prefix = value < 0 ? '-' : ''; |
61 | return lpad(prefix+Math.abs(value).toExponential(precision),' ',width); | 59 | return lpad(prefix+Math.abs(value).toExponential(precision),' ',width); |
62 | break; | ||
63 | case 'F': | 60 | case 'F': |
64 | case 'f': | 61 | case 'f': |
65 | prefix = value < 0 ? '-' : ''; | 62 | prefix = value < 0 ? '-' : ''; |
66 | return lpad(prefix+Math.abs(value).toFixed(precision),' ',width); | 63 | return lpad(prefix+Math.abs(value).toFixed(precision),' ',width); |
67 | break; | ||
68 | case 'g': | 64 | case 'g': |
69 | prefix = value < 0 ? '-' : ''; | 65 | prefix = value < 0 ? '-' : ''; |
70 | return lpad(prefix+Math.abs(value).toPrecision(precision),' ',width); | 66 | return lpad(prefix+Math.abs(value).toPrecision(precision),' ',width); |
71 | break; | ||
72 | default: | 67 | default: |
73 | return match; | 68 | return match; |
74 | } | 69 | } |
75 | 70 | ||
76 | }; | 71 | } |
77 | return fmt.replace(/%(\d+)?(\.(\d+))?(l?)([%scdfFeg])/g,format); | 72 | return fmt.replace(/%(\d+)?(\.(\d+))?(l?)([%scdfFeg])/g,format); |
78 | }; | 73 | } |