Skip to content

Commit

Permalink
Removing unnecessary typeof operators
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Feb 2, 2013
1 parent fb27fd3 commit 3f347fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
* @link http://filesizejs.com
* @module filesize
* @version 1.7.4
* @version 1.7.5
*/

(function (global) {
Expand All @@ -24,16 +24,16 @@
var base = 10,
bit, byte, i, neg, num, pos, regex, result, short, size, sizes, suffix, z, zero;

if (typeof arguments[2] !== "undefined") {
if (arguments[2] !== undefined) {
pos = arguments[1];
short = arguments[2];
}
else typeof arguments[1] === "boolean" ? short = arguments[1] : pos = arguments[1];

if (isNaN(arg) || (typeof pos !== "undefined" && isNaN(pos))) throw Error("Invalid arguments");
if (isNaN(arg) || (pos !== undefined && isNaN(pos))) throw Error("Invalid arguments");

short = (short === true);
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos, base));
pos = short ? 1 : (pos === undefined ? 2 : parseInt(pos, base));
num = Number(arg);
neg = (num < 0);
sizes = [["B", 0], ["Kb", 128], ["KB", 1024], ["Mb", 131072], ["MB", "1.049e+6"], ["Gb", "1.342e+8"], ["GB", "1.074e+9"], ["Tb", "1.374e+11"], ["TB", "1.1e+12"], ["Pb", "1.407e+14"], ["PB", "1.126e+15"]];
Expand All @@ -57,7 +57,7 @@
if (bit.test(suffix)) suffix = suffix.toLowerCase();
suffix = suffix.slice(0, 1);
z = regex.exec(result);
if (z !== null && typeof z[1] !== "undefined" && zero.test(z[1])) result = parseInt(result, base);
if (z !== null && z[1] !== undefined && zero.test(z[1])) result = parseInt(result, base);
}
result += suffix;
break;
Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "filesize",
"description": "JavaScript library to generate a human readable String describing the file size",
"version": "1.7.4",
"version": "1.7.5",
"homepage": "http://filesizejs.com",
"author": {
"name": "Jason Mulligan",
Expand Down
8 changes: 4 additions & 4 deletions src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
var base = 10,
bit, byte, i, neg, num, pos, regex, result, short, size, sizes, suffix, z, zero;

if (typeof arguments[2] !== "undefined") {
if (arguments[2] !== undefined) {
pos = arguments[1];
short = arguments[2];
}
else typeof arguments[1] === "boolean" ? short = arguments[1] : pos = arguments[1];

if (isNaN(arg) || (typeof pos !== "undefined" && isNaN(pos))) throw Error("Invalid arguments");
if (isNaN(arg) || (pos !== undefined && isNaN(pos))) throw Error("Invalid arguments");

short = (short === true);
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos, base));
pos = short ? 1 : (pos === undefined ? 2 : parseInt(pos, base));
num = Number(arg);
neg = (num < 0);
sizes = [["B", 0], ["Kb", 128], ["KB", 1024], ["Mb", 131072], ["MB", "1.049e+6"], ["Gb", "1.342e+8"], ["GB", "1.074e+9"], ["Tb", "1.374e+11"], ["TB", "1.1e+12"], ["Pb", "1.407e+14"], ["PB", "1.126e+15"]];
Expand All @@ -46,7 +46,7 @@
if (bit.test(suffix)) suffix = suffix.toLowerCase();
suffix = suffix.slice(0, 1);
z = regex.exec(result);
if (z !== null && typeof z[1] !== "undefined" && zero.test(z[1])) result = parseInt(result, base);
if (z !== null && z[1] !== undefined && zero.test(z[1])) result = parseInt(result, base);
}
result += suffix;
break;
Expand Down

0 comments on commit 3f347fa

Please sign in to comment.