From 97a497cfed5b1a7a1aee250b92ea8103e8c4d12f Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Fri, 2 Nov 2012 19:38:46 -0400 Subject: [PATCH 1/2] Extended size ranges to support Byte - PetaByte based on the new standard definitions --- lib/filesize.js | 5 +++-- lib/filesize.min.js | 4 ++-- package.json | 2 +- src/filesize.js | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/filesize.js b/lib/filesize.js index fa06c27..5de9f4b 100644 --- a/lib/filesize.js +++ b/lib/filesize.js @@ -6,7 +6,7 @@ * @license BSD-3 * @link https://github.com/avoidwork/filesize.js * @module filesize - * @version 1.6.7 + * @version 1.6.8 */ (function (global) { @@ -35,7 +35,7 @@ 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 = /\.(.*)/; @@ -43,6 +43,7 @@ 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) { diff --git a/lib/filesize.min.js b/lib/filesize.min.js index b33964d..4bcef52 100644 --- a/lib/filesize.min.js +++ b/lib/filesize.min.js @@ -6,6 +6,6 @@ * @license BSD-3 * @link https://github.com/avoidwork/filesize.js * @module filesize - * @version 1.6.7 + * @version 1.6.8 */ -(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); \ No newline at end of file +(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); \ No newline at end of file diff --git a/package.json b/package.json index 0d8acc4..44d0530 100644 --- a/package.json +++ b/package.json @@ -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.6.8", "homepage": "https://github.com/avoidwork/filesize.js", "author": { "name": "Jason Mulligan", diff --git a/src/filesize.js b/src/filesize.js index 4c28ab7..044b93b 100644 --- a/src/filesize.js +++ b/src/filesize.js @@ -24,7 +24,7 @@ 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 = /\.(.*)/; @@ -32,6 +32,7 @@ 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) { From 5341f0b8c7f529cb15b86bc035c066a3cb3ea83c Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Fri, 2 Nov 2012 19:39:43 -0400 Subject: [PATCH 2/2] Version bump --- lib/filesize.js | 2 +- lib/filesize.min.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/filesize.js b/lib/filesize.js index 5de9f4b..369cc0e 100644 --- a/lib/filesize.js +++ b/lib/filesize.js @@ -6,7 +6,7 @@ * @license BSD-3 * @link https://github.com/avoidwork/filesize.js * @module filesize - * @version 1.6.8 + * @version 1.7.0 */ (function (global) { diff --git a/lib/filesize.min.js b/lib/filesize.min.js index 4bcef52..96dbcf1 100644 --- a/lib/filesize.min.js +++ b/lib/filesize.min.js @@ -6,6 +6,6 @@ * @license BSD-3 * @link https://github.com/avoidwork/filesize.js * @module filesize - * @version 1.6.8 + * @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",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); \ No newline at end of file diff --git a/package.json b/package.json index 44d0530..a5f53b0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "filesize", "description": "JavaScript library to generate a human readable String describing the file size", - "version": "1.6.8", + "version": "1.7.0", "homepage": "https://github.com/avoidwork/filesize.js", "author": { "name": "Jason Mulligan",