Skip to content

Commit

Permalink
Merge pull request #9 from avoidwork/edge
Browse files Browse the repository at this point in the history
Refactored
  • Loading branch information
avoidwork committed Nov 2, 2012
2 parents d1cf422 + 5341f0b commit 69e24a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 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 https://github.com/avoidwork/filesize.js
* @module filesize
* @version 1.6.7
* @version 1.7.0
*/

(function (global) {
Expand Down Expand Up @@ -35,14 +35,15 @@
short = (short === true);
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos, base));
num = Number(arg);
sizes = [["B", 0], ["KB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776]];
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"]];
i = sizes.length;
result = "";
regex = /\.(.*)/;

while (i--) {
size = sizes[i][1];
suffix = sizes[i][0];
if (i > 3) size = Number(size);
if (num >= size) {
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
if (short) {
Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
* @link https://github.com/avoidwork/filesize.js
* @module filesize
* @version 1.6.7
* @version 1.7.0
*/
(function(e){"use strict";var t=function(e){var t=10,n,r,i,s,o,u,a,f,l,c;typeof arguments[2]!="undefined"?(n=arguments[1],r=arguments[2]):typeof arguments[1]=="boolean"?r=arguments[1]:n=arguments[1];if(isNaN(e)||typeof n!="undefined"&&isNaN(n))throw Error("Invalid arguments");r=r===!0,n=r?1:typeof n=="undefined"?2:parseInt(n,t),i=Number(e),s=[["B",0],["KB",1024],["MB",1048576],["GB",1073741824],["TB",1099511627776]],l=s.length,u="",a=/\.(.*)/;while(l--){o=s[l][1],f=s[l][0];if(i>=o){u=(f==="B"?i:i/o).toFixed(n),r&&(f=f.slice(0,1),c=a.exec(u),c!==null&&typeof c[1]!="undefined"&&c[1]==="0"&&(u=parseInt(u,t))),u+=f;break}}return u};switch(!0){case typeof exports!="undefined":module.exports=t;break;case typeof define=="function":define(function(){return t});break;default:e.filesize=t}})(this);
(function(e){"use strict";var t=function(e){var t=10,n,r,i,s,o,u,a,f,l,c;typeof arguments[2]!="undefined"?(n=arguments[1],r=arguments[2]):typeof arguments[1]=="boolean"?r=arguments[1]:n=arguments[1];if(isNaN(e)||typeof n!="undefined"&&isNaN(n))throw Error("Invalid arguments");r=r===!0,n=r?1:typeof n=="undefined"?2:parseInt(n,t),i=Number(e),s=[["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"]],l=s.length,u="",a=/\.(.*)/;while(l--){o=s[l][1],f=s[l][0],l>3&&(o=Number(o));if(i>=o){u=(f==="B"?i:i/o).toFixed(n),r&&(f=f.slice(0,1),c=a.exec(u),c!==null&&typeof c[1]!="undefined"&&c[1]==="0"&&(u=parseInt(u,t))),u+=f;break}}return u};switch(!0){case typeof exports!="undefined":module.exports=t;break;case typeof define=="function":define(function(){return t});break;default:e.filesize=t}})(this);
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.6.7",
"version": "1.7.0",
"homepage": "https://github.com/avoidwork/filesize.js",
"author": {
"name": "Jason Mulligan",
Expand Down
3 changes: 2 additions & 1 deletion src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
short = (short === true);
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos, base));
num = Number(arg);
sizes = [["B", 0], ["KB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776]];
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"]];
i = sizes.length;
result = "";
regex = /\.(.*)/;

while (i--) {
size = sizes[i][1];
suffix = sizes[i][0];
if (i > 3) size = Number(size);
if (num >= size) {
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
if (short) {
Expand Down

0 comments on commit 69e24a1

Please sign in to comment.