Skip to content

Commit

Permalink
Fixes #55 by avoiding type mutation, fixing CI tests by removing node…
Browse files Browse the repository at this point in the history
… 0.8.x
  • Loading branch information
avoidwork committed Oct 2, 2014
1 parent a8966f8 commit d3df0b0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- 0.8
- 0.10
3 changes: 2 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = function(grunt) {
],
dest : "lib/filesize.js"
}
},exec : {
},
exec : {
closure : {
cmd : "cd lib\nclosure-compiler --js <%= pkg.name %>.js --js_output_file <%= pkg.name %>.min.js --create_source_map ./<%= pkg.name %>.map"
},
Expand Down
21 changes: 11 additions & 10 deletions lib/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>
* @link http://filesizejs.com
* @module filesize
* @version 2.0.3
* @version 2.0.4
*/
( function ( global ) {
"use strict";
Expand All @@ -27,6 +27,7 @@ var bit = /b$/,
function filesize ( arg, descriptor ) {
var result = "",
skip = false,
val = 0,
e, base, bits, ceil, neg, num, round, unix, spacer, suffix, z, suffixes;

if ( isNaN( arg ) ) {
Expand Down Expand Up @@ -64,27 +65,27 @@ function filesize ( arg, descriptor ) {

// Exceeding supported length, time to reduce & multiply
if ( e > 8 ) {
result = result * ( 1000 * ( e - 8 ) );
e = 8;
val = val * ( 1000 * ( e - 8 ) );
e = 8;
}

if ( base === 2 ) {
result = num / Math.pow( 2, ( e * 10 ) );
val = num / Math.pow( 2, ( e * 10 ) );
}
else {
result = num / Math.pow( 1000, e );
val = num / Math.pow( 1000, e );
}

if ( bits ) {
result = ( result * 8 );
val = ( val * 8 );

if ( result > ceil ) {
result = result / ceil;
if ( val > ceil ) {
val = val / ceil;
e++;
}
}

result = result.toFixed( e > 0 ? round : 0 );
result = val.toFixed( e > 0 ? round : 0 );
suffix = si[bits ? "bits" : "bytes"][e];

if ( !skip && unix ) {
Expand All @@ -103,7 +104,7 @@ function filesize ( arg, descriptor ) {
}

if ( zero.test( z ) ) {
result = parseInt( result, radix );
result = parseInt( result, radix ).toString();
}

result += spacer + ( suffixes[suffix] || suffix );
Expand Down
4 changes: 2 additions & 2 deletions lib/filesize.map
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version":3,
"file":"filesize.min.js",
"lineCount":9,
"mappings":"A;;;;;;;AAUE,SAAS,CAAEA,CAAF,CAAW,CAgBtBC,QAASA,EAAS,CAAEC,CAAF,CAAOC,CAAP,CAAoB,CAAA,IACjCC,EAAS,EADwB,CAGjCC,CAHiC,CAGxBC,CAHwB,CAGlBC,CAHkB,CAGZC,CAHY,CAGPC,CAHO,CAGFC,CAHE,CAGKC,CAHL,CAGWC,CAHX,CAG8BC,CAEnE,IAAKC,KAAA,CAAOZ,CAAP,CAAL,CACC,KAAUa,MAAJ,CAAW,mBAAX,CAAN,CAGDZ,CAAA,CAAaA,CAAb,EAA2B,EAC3BG,EAAA,CAAmC,CAAA,CAAnC,GAAeH,CAAAG,KACfK,EAAA,CAAmC,CAAA,CAAnC,GAAeR,CAAAQ,KACfK,EAAA,CAAqCC,IAAAA,EAAxB,GAAAd,CAAAa,KAAA,CAAoCb,CAAAa,KAApC,CAA0DL,CAAA,CAAO,CAAP,CAAY,EACnFD,EAAA,CAAqCO,IAAAA,EAAxB,GAAAd,CAAAO,MAAA,CAAoCP,CAAAO,MAApC,CAA0DC,CAAA,CAAO,CAAP,CAAY,CACnFC,EAAA,CAAqCK,IAAAA,EAAxB,GAAAd,CAAAS,OAAA,CAAoCT,CAAAS,OAApC,CAA0DD,CAAA,CAAO,EAAP,CAAY,GACnFE,EAAA,CAAqCI,IAAAA,EAAxB,GAAAd,CAAAU,SAAA,CAAoCV,CAAAU,SAApC,CAA0D,EACvEJ,EAAA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A,MAAA,CAAA,GAAA,CADA,OAEA,2BAAA,MAAA,CAAA,GAAA,CAFA,CAMe,YAAxB,GAAK,MAAOY,QAAZ,CACCC,MAAAD,QADD,CACkBrC,CADlB,CAG4B,UAAvB,GAAK,MAAOuC,OAAZ,CACJA,MAAA,CAAQ,QAAS,EAAG,CACnB,MAAOvC,EADY,CAApB,CADI,CAMJD,CAAAC,SANI,CAMcA,CAtIG,CAApB,CAAA,CAyIG,IAzIH;",
"sources":["filesize.js"],
"names":["global","filesize","arg","descriptor","result","e","bits","ceil","neg","num","round","unix","spacer","suffixes","isNaN","Error","base","undefined","Number","suffix","Math","floor","log","pow","toFixed","si","bit","test","toLowerCase","charAt","z","replace","left","zero","parseInt","radix","exports","module","define"]
"names":["global","filesize","arg","descriptor","result","val","e","bits","neg","num","round","unix","spacer","suffixes","isNaN","Error","base","undefined","Number","ceil","suffix","Math","floor","log","pow","toFixed","si","bit","test","toLowerCase","charAt","z","replace","left","zero","parseInt","radix","toString","exports","module","define"]
}
6 changes: 3 additions & 3 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": "2.0.3",
"version": "2.0.4",
"homepage": "http://filesizejs.com",
"author": {
"name": "Jason Mulligan",
Expand Down
19 changes: 10 additions & 9 deletions src/filesize.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
function filesize ( arg, descriptor ) {
var result = "",
skip = false,
val = 0,
e, base, bits, ceil, neg, num, round, unix, spacer, suffix, z, suffixes;

if ( isNaN( arg ) ) {
Expand Down Expand Up @@ -46,27 +47,27 @@ function filesize ( arg, descriptor ) {

// Exceeding supported length, time to reduce & multiply
if ( e > 8 ) {
result = result * ( 1000 * ( e - 8 ) );
e = 8;
val = val * ( 1000 * ( e - 8 ) );
e = 8;
}

if ( base === 2 ) {
result = num / Math.pow( 2, ( e * 10 ) );
val = num / Math.pow( 2, ( e * 10 ) );
}
else {
result = num / Math.pow( 1000, e );
val = num / Math.pow( 1000, e );
}

if ( bits ) {
result = ( result * 8 );
val = ( val * 8 );

if ( result > ceil ) {
result = result / ceil;
if ( val > ceil ) {
val = val / ceil;
e++;
}
}

result = result.toFixed( e > 0 ? round : 0 );
result = val.toFixed( e > 0 ? round : 0 );
suffix = si[bits ? "bits" : "bytes"][e];

if ( !skip && unix ) {
Expand All @@ -85,7 +86,7 @@ function filesize ( arg, descriptor ) {
}

if ( zero.test( z ) ) {
result = parseInt( result, radix );
result = parseInt( result, radix ).toString();
}

result += spacer + ( suffixes[suffix] || suffix );
Expand Down

0 comments on commit d3df0b0

Please sign in to comment.