Skip to content

Commit 97a497c

Browse files
committed
Extended size ranges to support Byte - PetaByte based on the new standard definitions
1 parent f487a26 commit 97a497c

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

lib/filesize.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
77
* @link https://github.com/avoidwork/filesize.js
88
* @module filesize
9-
* @version 1.6.7
9+
* @version 1.6.8
1010
*/
1111

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

4343
while (i--) {
4444
size = sizes[i][1];
4545
suffix = sizes[i][0];
46+
if (i > 3) size = Number(size);
4647
if (num >= size) {
4748
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
4849
if (short) {

lib/filesize.min.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* @license BSD-3 <http://opensource.org/licenses/BSD-3-Clause>
77
* @link https://github.com/avoidwork/filesize.js
88
* @module filesize
9-
* @version 1.6.7
9+
* @version 1.6.8
1010
*/
11-
(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);
11+
(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);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "filesize",
33
"description": "JavaScript library to generate a human readable String describing the file size",
4-
"version": "1.6.7",
4+
"version": "1.6.8",
55
"homepage": "https://github.com/avoidwork/filesize.js",
66
"author": {
77
"name": "Jason Mulligan",

src/filesize.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@
2424
short = (short === true);
2525
pos = short ? 1 : (typeof pos === "undefined" ? 2 : parseInt(pos, base));
2626
num = Number(arg);
27-
sizes = [["B", 0], ["KB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776]];
27+
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"]];
2828
i = sizes.length;
2929
result = "";
3030
regex = /\.(.*)/;
3131

3232
while (i--) {
3333
size = sizes[i][1];
3434
suffix = sizes[i][0];
35+
if (i > 3) size = Number(size);
3536
if (num >= size) {
3637
result = (suffix === "B" ? num : (num / size)).toFixed(pos);
3738
if (short) {

0 commit comments

Comments
 (0)